modifying how onLoad events are sent to plugins to properly handle IFrames.

Change-Id: I634ae9c2e18e03c95dff435679f547d37c6f430e
diff --git a/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp b/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp
index 103dc4b..c9e712e 100644
--- a/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp
+++ b/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp
@@ -295,7 +295,7 @@
     }
 
     AssetManager* am = globalAssetManager();
-    
+
     // Check to see if the error code was not generated internally
     WebFrame::RAW_RES_ID id = WebFrame::NODOMAIN;
     if ((error.errorCode() == ErrorFile ||
@@ -335,7 +335,7 @@
     // Replace all occurances of %s with the failing url.
     String s = UTF8Encoding().decode((const char*)a->getBuffer(false), a->getLength());
     s = s.replace("%s", String(url.data(), url.size()));
-    
+
     // Replace all occurances of %e with the error text
     s = s.replace("%e", error.localizedDescription());
 
@@ -563,10 +563,13 @@
 // This is just a notification that the progress has finished. Don't call
 // setProgress(1) because postProgressEstimateChangedNotification will do so.
 void FrameLoaderClientAndroid::postProgressFinishedNotification() {
+    WebViewCore* core =  WebViewCore::getWebViewCore(m_frame->view());
     if (!m_frame->tree()->parent()) {
         // only need to notify Java for the top frame
-        WebViewCore::getWebViewCore(m_frame->view())->notifyProgressFinished();
+        core->notifyProgressFinished();
     }
+    // notify plugins that the frame has loaded
+    core->notifyPluginsOnFrameLoad(m_frame);
 }
 
 void FrameLoaderClientAndroid::setMainFrameDocumentReady(bool) {
@@ -666,7 +669,7 @@
 bool FrameLoaderClientAndroid::canHandleRequest(const ResourceRequest& request) const {
     ASSERT(m_frame);
     // Don't allow hijacking of intrapage navigation
-    if (WebCore::equalIgnoringFragmentIdentifier(request.url(), m_frame->loader()->url())) 
+    if (WebCore::equalIgnoringFragmentIdentifier(request.url(), m_frame->loader()->url()))
         return true;
 
     // Don't allow hijacking of iframe urls that are http or https
@@ -865,7 +868,7 @@
     newFrame->tree()->setName(name);
     // Create a new FrameView and WebFrameView for the child frame to draw into.
     RefPtr<FrameView> frameView = FrameView::create(newFrame);
-    WebFrameView* webFrameView = new WebFrameView(frameView.get(), 
+    WebFrameView* webFrameView = new WebFrameView(frameView.get(),
             WebViewCore::getWebViewCore(parent->view()));
     // frameView Retains webFrameView, so call Release for webFrameView
     Release(webFrameView);
@@ -878,7 +881,7 @@
     // The creation of the frame may have run arbitrary JavaScript that removed it from the page already.
     if (!pFrame->page())
         return 0;
- 
+
     parent->loader()->loadURLIntoChildFrame(url, referrer, pFrame.get());
 
     // onLoad may cuase the frame to be removed from the document. Allow the RefPtr to delete the child frame.
@@ -1037,7 +1040,7 @@
 // This function is used to re-attach Javascript<->native code classes.
 void FrameLoaderClientAndroid::windowObjectCleared() {
     ASSERT(m_frame);
-    LOGV("::WebCore:: windowObjectCleared called on frame %p for %s\n", 
+    LOGV("::WebCore:: windowObjectCleared called on frame %p for %s\n",
     		m_frame, m_frame->loader()->url().string().ascii().data());
     m_webFrame->windowObjectCleared(m_frame);
 }
@@ -1052,11 +1055,11 @@
 
 // functions new to Nov-07 tip of tree merge:
 void FrameLoaderClientAndroid::didPerformFirstNavigation() const {
-    // This seems to be just a notification that the UI can listen to, to 
-    // know if the user has performed first navigation action. 
-    // It is called from 
+    // This seems to be just a notification that the UI can listen to, to
+    // know if the user has performed first navigation action.
+    // It is called from
     // void FrameLoader::addBackForwardItemClippedAtTarget(bool doClip)
-    // "Navigation" here means a transition from one page to another that 
+    // "Navigation" here means a transition from one page to another that
     // ends up in the back/forward list.
 }
 
diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp
index 670b64a..2f9a4fc 100644
--- a/WebKit/android/jni/WebViewCore.cpp
+++ b/WebKit/android/jni/WebViewCore.cpp
@@ -899,12 +899,6 @@
     m_check_domtree_version = true;
     updateFrameCache();
     sendNotifyProgressFinished();
-
-    // trigger an event notifying the plugins that the page has loaded
-    ANPEvent event;
-    SkANP::InitEvent(&event, kLifecycle_ANPEventType);
-    event.data.lifecycle.action = kOnLoad_ANPLifecycleAction;
-    sendPluginEvent(event);
 }
 
 void WebViewCore::doMaxScroll(CacheBuilder::Direction dir)
@@ -1226,6 +1220,36 @@
     }
 }
 
+void WebViewCore::notifyPluginsOnFrameLoad(const Frame* frame) {
+    // if frame is the parent then notify all plugins
+    if (!frame->tree()->parent()) {
+        // trigger an event notifying the plugins that the page has loaded
+        ANPEvent event;
+        SkANP::InitEvent(&event, kLifecycle_ANPEventType);
+        event.data.lifecycle.action = kOnLoad_ANPLifecycleAction;
+        sendPluginEvent(event);
+    }
+    // else if frame's parent has completed
+    else if (!frame->tree()->parent()->loader()->isLoading()) {
+        // send to all plugins who have this frame in their heirarchy
+        PluginWidgetAndroid** iter = m_plugins.begin();
+        PluginWidgetAndroid** stop = m_plugins.end();
+        for (; iter < stop; ++iter) {
+            Frame* currentFrame = (*iter)->pluginView()->parentFrame();
+            while (currentFrame) {
+                if (frame == currentFrame) {
+                    ANPEvent event;
+                    SkANP::InitEvent(&event, kLifecycle_ANPEventType);
+                    event.data.lifecycle.action = kOnLoad_ANPLifecycleAction;
+                    (*iter)->sendEvent(event);
+                    break;
+                }
+                currentFrame = currentFrame->tree()->parent();
+            }
+        }
+    }
+}
+
 void WebViewCore::sendPluginVisibleScreen()
 {
     ANPRectI visibleRect;
diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h
index 97018f0..697ed59 100644
--- a/WebKit/android/jni/WebViewCore.h
+++ b/WebKit/android/jni/WebViewCore.h
@@ -341,6 +341,9 @@
         // send the current screen size/zoom to all of the plugins in our list
         void sendPluginVisibleScreen();
 
+	// send onLoad event to plugins who are descendents of the given frame
+        void notifyPluginsOnFrameLoad(const Frame*);
+
         // send this event to all of the plugins in our list
         void sendPluginEvent(const ANPEvent&);