summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-05 12:50:07 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-05 12:50:07 +0000
commitdabb0d1ddd62548ad899caf16ea4ac9a0f68593f (patch)
treec848ab25304cd520c7dca09083d8872052d88adf
parenta22fa6825a1afeace5a9110ab4c732fd3c3ebe2c (diff)
downloadchromium_src-dabb0d1ddd62548ad899caf16ea4ac9a0f68593f.zip
chromium_src-dabb0d1ddd62548ad899caf16ea4ac9a0f68593f.tar.gz
chromium_src-dabb0d1ddd62548ad899caf16ea4ac9a0f68593f.tar.bz2
Implement the frame id required for the web navigation api.
BUG=50943 TEST=*.WebNavigationEvents Review URL: http://codereview.chromium.org/3561008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61503 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/extension_webnavigation_api.cc33
-rw-r--r--chrome/browser/extensions/extension_webnavigation_api.h3
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc13
-rw-r--r--chrome/browser/renderer_host/render_view_host.h6
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.h2
-rw-r--r--chrome/browser/tab_contents/provisional_load_details.cc6
-rw-r--r--chrome/browser/tab_contents/provisional_load_details.h6
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc17
-rw-r--r--chrome/browser/tab_contents/tab_contents.h2
-rw-r--r--chrome/common/render_messages_internal.h8
-rw-r--r--chrome/common/render_messages_params.cc5
-rw-r--r--chrome/common/render_messages_params.h4
-rw-r--r--chrome/renderer/render_view.cc7
-rw-r--r--chrome/test/data/extensions/api_test/webnavigation/navigation/iframe/d.html10
-rw-r--r--chrome/test/data/extensions/api_test/webnavigation/navigation/iframe/e.html1
-rw-r--r--chrome/test/data/extensions/api_test/webnavigation/navigation/iframe/f.html3
-rw-r--r--chrome/test/data/extensions/api_test/webnavigation/navigation/iframe/g.html1
-rw-r--r--chrome/test/data/extensions/api_test/webnavigation/navigation/iframeFail/a.html1
-rw-r--r--chrome/test/data/extensions/api_test/webnavigation/navigation/iframeFail/b.html3
-rw-r--r--chrome/test/data/extensions/api_test/webnavigation/navigation/iframeFail/d.html1
-rw-r--r--chrome/test/data/extensions/api_test/webnavigation/navigation/test.html213
21 files changed, 284 insertions, 61 deletions
diff --git a/chrome/browser/extensions/extension_webnavigation_api.cc b/chrome/browser/extensions/extension_webnavigation_api.cc
index 589d5b6..6281a06 100644
--- a/chrome/browser/extensions/extension_webnavigation_api.cc
+++ b/chrome/browser/extensions/extension_webnavigation_api.cc
@@ -21,6 +21,21 @@
namespace keys = extension_webnavigation_api_constants;
+namespace {
+
+// Returns 0 if the navigation happens in the main frame, or the frame ID
+// modulo 32 bits otherwise.
+int GetFrameId(ProvisionalLoadDetails* details) {
+ return details->main_frame() ? 0 : static_cast<int>(details->frame_id());
+}
+
+// Returns |time| as milliseconds since the epoch.
+double MilliSecondsFromTime(const base::Time& time) {
+ return 1000 * time.ToDoubleT();
+}
+
+} // namespace
+
// static
ExtensionWebNavigationEventRouter*
ExtensionWebNavigationEventRouter::GetInstance() {
@@ -75,11 +90,9 @@ void ExtensionWebNavigationEventRouter::FrameProvisionalLoadStart(
ExtensionTabUtil::GetTabId(controller->tab_contents()));
dict->SetString(keys::kUrlKey,
details->url().spec());
- dict->SetInteger(keys::kFrameIdKey, 0);
+ dict->SetInteger(keys::kFrameIdKey, GetFrameId(details));
dict->SetInteger(keys::kRequestIdKey, 0);
- dict->SetReal(keys::kTimeStampKey,
- static_cast<double>(
- (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()));
+ dict->SetReal(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
args.Append(dict);
std::string json_args;
@@ -96,16 +109,14 @@ void ExtensionWebNavigationEventRouter::FrameProvisionalLoadCommitted(
ExtensionTabUtil::GetTabId(controller->tab_contents()));
dict->SetString(keys::kUrlKey,
details->url().spec());
- dict->SetInteger(keys::kFrameIdKey, 0);
+ dict->SetInteger(keys::kFrameIdKey, GetFrameId(details));
dict->SetString(keys::kTransitionTypeKey,
PageTransition::CoreTransitionString(
details->transition_type()));
dict->SetString(keys::kTransitionQualifiersKey,
PageTransition::QualifierString(
details->transition_type()));
- dict->SetReal(keys::kTimeStampKey,
- static_cast<double>(
- (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()));
+ dict->SetReal(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
args.Append(dict);
std::string json_args;
@@ -122,12 +133,10 @@ void ExtensionWebNavigationEventRouter::FailProvisionalLoadWithError(
ExtensionTabUtil::GetTabId(controller->tab_contents()));
dict->SetString(keys::kUrlKey,
details->url().spec());
- dict->SetInteger(keys::kFrameIdKey, 0);
+ dict->SetInteger(keys::kFrameIdKey, GetFrameId(details));
dict->SetString(keys::kErrorKey,
std::string(net::ErrorToString(details->error_code())));
- dict->SetReal(keys::kTimeStampKey,
- static_cast<double>(
- (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()));
+ dict->SetReal(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
args.Append(dict);
std::string json_args;
diff --git a/chrome/browser/extensions/extension_webnavigation_api.h b/chrome/browser/extensions/extension_webnavigation_api.h
index 95ba032..21cfb16 100644
--- a/chrome/browser/extensions/extension_webnavigation_api.h
+++ b/chrome/browser/extensions/extension_webnavigation_api.h
@@ -10,6 +10,8 @@
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBNAVIGATION_API_H_
#pragma once
+#include <map>
+
#include "base/singleton.h"
#include "chrome/browser/extensions/extension_function.h"
#include "chrome/common/notification_observer.h"
@@ -18,6 +20,7 @@
class NavigationController;
class ProvisionalLoadDetails;
+class TabContents;
// Observes navigation notifications and routes them as events to the extension
// system.
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index a702b08..143bc1a 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -1166,7 +1166,8 @@ void RenderViewHost::OnMsgDidRunInsecureContent(
resource_delegate->DidRunInsecureContent(security_origin);
}
-void RenderViewHost::OnMsgDidStartProvisionalLoadForFrame(bool is_main_frame,
+void RenderViewHost::OnMsgDidStartProvisionalLoadForFrame(long long frame_id,
+ bool is_main_frame,
const GURL& url) {
GURL validated_url(url);
FilterURL(ChildProcessSecurityPolicy::GetInstance(),
@@ -1175,12 +1176,13 @@ void RenderViewHost::OnMsgDidStartProvisionalLoadForFrame(bool is_main_frame,
RenderViewHostDelegate::Resource* resource_delegate =
delegate_->GetResourceDelegate();
if (resource_delegate) {
- resource_delegate->DidStartProvisionalLoadForFrame(this, is_main_frame,
- validated_url);
+ resource_delegate->DidStartProvisionalLoadForFrame(
+ this, frame_id, is_main_frame, validated_url);
}
}
void RenderViewHost::OnMsgDidFailProvisionalLoadWithError(
+ long long frame_id,
bool is_main_frame,
int error_code,
const GURL& url,
@@ -1188,7 +1190,8 @@ void RenderViewHost::OnMsgDidFailProvisionalLoadWithError(
LOG(INFO) << "Failed Provisional Load: " << url.possibly_invalid_spec()
<< ", error_code: " << error_code
<< " is_main_frame: " << is_main_frame
- << " showing_repost_interstitial: " << showing_repost_interstitial;
+ << " showing_repost_interstitial: " << showing_repost_interstitial
+ << " frame_id: " << frame_id;
GURL validated_url(url);
FilterURL(ChildProcessSecurityPolicy::GetInstance(),
process()->id(), &validated_url);
@@ -1197,7 +1200,7 @@ void RenderViewHost::OnMsgDidFailProvisionalLoadWithError(
delegate_->GetResourceDelegate();
if (resource_delegate) {
resource_delegate->DidFailProvisionalLoadWithError(
- this, is_main_frame, error_code, validated_url,
+ this, frame_id, is_main_frame, error_code, validated_url,
showing_repost_interstitial);
}
}
diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h
index b9bf703..b83ccce 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -550,9 +550,11 @@ class RenderViewHost : public RenderWidgetHost {
const std::string& security_info);
void OnMsgDidDisplayInsecureContent();
void OnMsgDidRunInsecureContent(const std::string& security_origin);
- void OnMsgDidStartProvisionalLoadForFrame(bool main_frame,
+ void OnMsgDidStartProvisionalLoadForFrame(long long frame_id,
+ bool main_frame,
const GURL& url);
- void OnMsgDidFailProvisionalLoadWithError(bool main_frame,
+ void OnMsgDidFailProvisionalLoadWithError(long long frame_id,
+ bool main_frame,
int error_code,
const GURL& url,
bool showing_repost_interstitial);
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h
index 58c94ad..28a94de 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.h
+++ b/chrome/browser/renderer_host/render_view_host_delegate.h
@@ -302,6 +302,7 @@ class RenderViewHostDelegate {
// The RenderView is starting a provisional load.
virtual void DidStartProvisionalLoadForFrame(
RenderViewHost* render_view_host,
+ long long frame_id,
bool is_main_frame,
const GURL& url) = 0;
@@ -341,6 +342,7 @@ class RenderViewHostDelegate {
// The RenderView failed a provisional load with an error.
virtual void DidFailProvisionalLoadWithError(
RenderViewHost* render_view_host,
+ long long frame_id,
bool is_main_frame,
int error_code,
const GURL& url,
diff --git a/chrome/browser/tab_contents/provisional_load_details.cc b/chrome/browser/tab_contents/provisional_load_details.cc
index e1e85d2..dedf3e8 100644
--- a/chrome/browser/tab_contents/provisional_load_details.cc
+++ b/chrome/browser/tab_contents/provisional_load_details.cc
@@ -11,7 +11,8 @@ ProvisionalLoadDetails::ProvisionalLoadDetails(bool is_main_frame,
bool is_in_page_navigation,
const GURL& url,
const std::string& security_info,
- bool is_content_filtered)
+ bool is_content_filtered,
+ long long frame_id)
: error_code_(net::OK),
transition_type_(PageTransition::LINK),
url_(url),
@@ -21,7 +22,8 @@ ProvisionalLoadDetails::ProvisionalLoadDetails(bool is_main_frame,
ssl_cert_status_(0),
ssl_security_bits_(-1),
ssl_connection_status_(0),
- is_content_filtered_(is_content_filtered) {
+ is_content_filtered_(is_content_filtered),
+ frame_id_(frame_id) {
SSLManager::DeserializeSecurityInfo(security_info,
&ssl_cert_id_,
&ssl_cert_status_,
diff --git a/chrome/browser/tab_contents/provisional_load_details.h b/chrome/browser/tab_contents/provisional_load_details.h
index 2073db0..a9b0baa 100644
--- a/chrome/browser/tab_contents/provisional_load_details.h
+++ b/chrome/browser/tab_contents/provisional_load_details.h
@@ -27,7 +27,8 @@ class ProvisionalLoadDetails {
bool in_page_navigation,
const GURL& url,
const std::string& security_info,
- bool is_filtered);
+ bool is_filtered,
+ long long frame_id);
virtual ~ProvisionalLoadDetails() { }
void set_error_code(int error_code) { error_code_ = error_code; }
@@ -56,6 +57,8 @@ class ProvisionalLoadDetails {
bool is_content_filtered() const { return is_content_filtered_; }
+ long long frame_id() const { return frame_id_; }
+
private:
int error_code_;
PageTransition::Type transition_type_;
@@ -67,6 +70,7 @@ class ProvisionalLoadDetails {
int ssl_security_bits_;
int ssl_connection_status_;
bool is_content_filtered_;
+ long long frame_id_;
DISALLOW_COPY_AND_ASSIGN(ProvisionalLoadDetails);
};
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 486e52c..3c05931 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -2093,11 +2093,12 @@ void TabContents::OnSetSuggestResult(int32 page_id, const std::string& result) {
void TabContents::DidStartProvisionalLoadForFrame(
RenderViewHost* render_view_host,
+ long long frame_id,
bool is_main_frame,
const GURL& url) {
ProvisionalLoadDetails details(is_main_frame,
controller_.IsURLInPageNavigation(url),
- url, std::string(), false);
+ url, std::string(), false, frame_id);
NotificationService::current()->Notify(
NotificationType::FRAME_PROVISIONAL_LOAD_START,
Source<NavigationController>(&controller_),
@@ -2156,6 +2157,7 @@ void TabContents::DidRunInsecureContent(const std::string& security_origin) {
void TabContents::DidFailProvisionalLoadWithError(
RenderViewHost* render_view_host,
+ long long frame_id,
bool is_main_frame,
int error_code,
const GURL& url,
@@ -2201,7 +2203,7 @@ void TabContents::DidFailProvisionalLoadWithError(
// Send out a notification that we failed a provisional load with an error.
ProvisionalLoadDetails details(is_main_frame,
controller_.IsURLInPageNavigation(url),
- url, std::string(), false);
+ url, std::string(), false, frame_id);
details.set_error_code(error_code);
NotificationService::current()->Notify(
@@ -2429,9 +2431,14 @@ void TabContents::DidNavigate(RenderViewHost* rvh,
// different from the NAV_ENTRY_COMMITTED notification which doesn't include
// the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
if (details.type != NavigationType::NAV_IGNORE) {
- ProvisionalLoadDetails load_details(details.is_main_frame,
- details.is_in_page,
- params.url, std::string(), false);
+ // For AUTO_SUBFRAME navigations, an event for the main frame is generated
+ // that is not recorded in the navigation history. For the purpose of
+ // tracking navigation events, we treat this event as a sub frame navigation
+ // event.
+ bool is_main_frame = did_navigate ? details.is_main_frame : false;
+ ProvisionalLoadDetails load_details(
+ is_main_frame, details.is_in_page, params.url, std::string(), false,
+ params.frame_id);
load_details.set_transition_type(params.transition);
// Whether or not a page transition was triggered by going backward or
// forward in the history is only stored in the navigation controller's
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index b8264fc..f770c42 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -869,6 +869,7 @@ class TabContents : public PageNavigator,
// RenderViewHostDelegate::Resource implementation.
virtual void DidStartProvisionalLoadForFrame(RenderViewHost* render_view_host,
+ long long frame_id,
bool is_main_frame,
const GURL& url);
virtual void DidStartReceivingResourceResponse(
@@ -887,6 +888,7 @@ class TabContents : public PageNavigator,
virtual void DidRunInsecureContent(const std::string& security_origin);
virtual void DidFailProvisionalLoadWithError(
RenderViewHost* render_view_host,
+ long long frame_id,
bool is_main_frame,
int error_code,
const GURL& url,
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index b2cb0bf..326202a 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -1234,18 +1234,20 @@ IPC_BEGIN_MESSAGES(ViewHost)
std::string /* security_origin */)
// Sent when the renderer starts a provisional load for a frame.
- IPC_MESSAGE_ROUTED2(ViewHostMsg_DidStartProvisionalLoadForFrame,
+ IPC_MESSAGE_ROUTED3(ViewHostMsg_DidStartProvisionalLoadForFrame,
+ long long /* frame_id */,
bool /* true if it is the main frame */,
GURL /* url */)
// Sent when the renderer fails a provisional load with an error.
- IPC_MESSAGE_ROUTED4(ViewHostMsg_DidFailProvisionalLoadWithError,
+ IPC_MESSAGE_ROUTED5(ViewHostMsg_DidFailProvisionalLoadWithError,
+ long long /* frame_id */,
bool /* true if it is the main frame */,
int /* error_code */,
GURL /* url */,
bool /* true if the failure is the result of
navigating to a POST again and we're going to
- show the POST interstitial */ )
+ show the POST interstitial */)
// Tells the render view that a ViewHostMsg_PaintAtSize message was
// processed, and the DIB is ready for use. |tag| has the same value that
diff --git a/chrome/common/render_messages_params.cc b/chrome/common/render_messages_params.cc
index 074579b..c5b4aa3 100644
--- a/chrome/common/render_messages_params.cc
+++ b/chrome/common/render_messages_params.cc
@@ -24,6 +24,7 @@ ViewMsg_Navigate_Params::~ViewMsg_Navigate_Params() {
ViewHostMsg_FrameNavigate_Params::ViewHostMsg_FrameNavigate_Params()
: page_id(0),
+ frame_id(0),
transition(PageTransition::TYPED),
should_update_history(false),
gesture(NavigationGestureUser),
@@ -716,6 +717,7 @@ void ParamTraits<ViewHostMsg_GetSearchProviderInstallState_Params>::Log(
void ParamTraits<ViewHostMsg_FrameNavigate_Params>::Write(Message* m,
const param_type& p) {
WriteParam(m, p.page_id);
+ WriteParam(m, p.frame_id);
WriteParam(m, p.url);
WriteParam(m, p.referrer);
WriteParam(m, p.transition);
@@ -738,6 +740,7 @@ bool ParamTraits<ViewHostMsg_FrameNavigate_Params>::Read(const Message* m,
param_type* p) {
return
ReadParam(m, iter, &p->page_id) &&
+ ReadParam(m, iter, &p->frame_id) &&
ReadParam(m, iter, &p->url) &&
ReadParam(m, iter, &p->referrer) &&
ReadParam(m, iter, &p->transition) &&
@@ -760,6 +763,8 @@ void ParamTraits<ViewHostMsg_FrameNavigate_Params>::Log(const param_type& p,
l->append("(");
LogParam(p.page_id, l);
l->append(", ");
+ LogParam(p.frame_id, l);
+ l->append(", ");
LogParam(p.url, l);
l->append(", ");
LogParam(p.referrer, l);
diff --git a/chrome/common/render_messages_params.h b/chrome/common/render_messages_params.h
index 1c49b66..2b0c0d0 100644
--- a/chrome/common/render_messages_params.h
+++ b/chrome/common/render_messages_params.h
@@ -205,6 +205,10 @@ struct ViewHostMsg_FrameNavigate_Params {
// iframes are loaded automatically.
int32 page_id;
+ // The frame ID for this navigation. The frame ID uniquely identifies the
+ // frame the navigation happened in for a given renderer.
+ long long frame_id;
+
// URL of the page being loaded.
GURL url;
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 38a44f3..495a1f3 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -1311,6 +1311,7 @@ void RenderView::UpdateURL(WebFrame* frame) {
params.http_status_code = response.httpStatusCode();
params.is_post = false;
params.page_id = page_id_;
+ params.frame_id = frame->identifier();
params.is_content_filtered = response.isContentFiltered();
params.was_within_same_page = navigation_state->was_within_same_page();
if (!navigation_state->security_info().empty()) {
@@ -2884,7 +2885,7 @@ void RenderView::didStartProvisionalLoad(WebFrame* frame) {
}
Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
- routing_id_, is_top_most, ds->request().url()));
+ routing_id_, frame->identifier(), is_top_most, ds->request().url()));
}
void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
@@ -2922,8 +2923,8 @@ void RenderView::didFailProvisionalLoad(WebFrame* frame,
(error.reason == net::ERR_CACHE_MISS &&
EqualsASCII(failed_request.httpMethod(), "POST"));
Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
- routing_id_, !frame->parent(), error.reason, error.unreachableURL,
- show_repost_interstitial));
+ routing_id_, frame->identifier(), !frame->parent(), error.reason,
+ error.unreachableURL, show_repost_interstitial));
// Don't display an error page if this is simply a cancelled load. Aside
// from being dumb, WebCore doesn't expect it and it will cause a crash.
diff --git a/chrome/test/data/extensions/api_test/webnavigation/navigation/iframe/d.html b/chrome/test/data/extensions/api_test/webnavigation/navigation/iframe/d.html
new file mode 100644
index 0000000..a2d0b44
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/webnavigation/navigation/iframe/d.html
@@ -0,0 +1,10 @@
+<html><body>
+<script>
+ window.setTimeout(function() {
+ var iframe = document.createElement('iframe');
+ iframe.src = "f.html";
+ var div = document.getElementById('f');
+ div.appendChild(iframe);
+ }, 500);
+</script>
+<iframe src="e.html"></iframe><div id="f"></div></body></html>
diff --git a/chrome/test/data/extensions/api_test/webnavigation/navigation/iframe/e.html b/chrome/test/data/extensions/api_test/webnavigation/navigation/iframe/e.html
new file mode 100644
index 0000000..18ecdcb
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/webnavigation/navigation/iframe/e.html
@@ -0,0 +1 @@
+<html></html>
diff --git a/chrome/test/data/extensions/api_test/webnavigation/navigation/iframe/f.html b/chrome/test/data/extensions/api_test/webnavigation/navigation/iframe/f.html
new file mode 100644
index 0000000..b623f77
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/webnavigation/navigation/iframe/f.html
@@ -0,0 +1,3 @@
+<script>
+ window.setTimeout('document.location = "g.html";', 500);
+</script>
diff --git a/chrome/test/data/extensions/api_test/webnavigation/navigation/iframe/g.html b/chrome/test/data/extensions/api_test/webnavigation/navigation/iframe/g.html
new file mode 100644
index 0000000..18ecdcb
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/webnavigation/navigation/iframe/g.html
@@ -0,0 +1 @@
+<html></html>
diff --git a/chrome/test/data/extensions/api_test/webnavigation/navigation/iframeFail/a.html b/chrome/test/data/extensions/api_test/webnavigation/navigation/iframeFail/a.html
new file mode 100644
index 0000000..c5c157d
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/webnavigation/navigation/iframeFail/a.html
@@ -0,0 +1 @@
+<html><body><iframe src="b.html"></iframe></body></html>
diff --git a/chrome/test/data/extensions/api_test/webnavigation/navigation/iframeFail/b.html b/chrome/test/data/extensions/api_test/webnavigation/navigation/iframeFail/b.html
new file mode 100644
index 0000000..d6e86d8
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/webnavigation/navigation/iframeFail/b.html
@@ -0,0 +1,3 @@
+<script>
+ window.setTimeout('document.location = "c.html";', 500);
+</script>
diff --git a/chrome/test/data/extensions/api_test/webnavigation/navigation/iframeFail/d.html b/chrome/test/data/extensions/api_test/webnavigation/navigation/iframeFail/d.html
new file mode 100644
index 0000000..466484f
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/webnavigation/navigation/iframeFail/d.html
@@ -0,0 +1 @@
+<html><body><iframe src="c.html"></iframe></body></html>
diff --git a/chrome/test/data/extensions/api_test/webnavigation/navigation/test.html b/chrome/test/data/extensions/api_test/webnavigation/navigation/test.html
index 431b4e7..4042947 100644
--- a/chrome/test/data/extensions/api_test/webnavigation/navigation/test.html
+++ b/chrome/test/data/extensions/api_test/webnavigation/navigation/test.html
@@ -1,10 +1,14 @@
<script>
var expectedEventData;
var capturedEventData;
+var nextFrameId;
+var frameIds;
function expect(data) {
expectedEventData = data;
capturedEventData = [];
+ nextFrameId = 1;
+ frameIds = {};
}
function checkExpectations() {
@@ -16,39 +20,31 @@ function checkExpectations() {
chrome.test.succeed();
}
-chrome.experimental.webNavigation.onBeforeNavigate.addListener(
- function(details) {
- console.log('---onBeforeNavigate: ' + details.url);
- // normalize details.
- details.timeStamp = 0;
- if (details.frameId != 0) {
- details.frameId = 1;
- }
- capturedEventData.push(["onBeforeNavigate", details]);
- checkExpectations();
-});
-
-chrome.experimental.webNavigation.onCommitted.addListener(function(details) {
- console.log('---onCommitted: ' + details.url);
+function captureEvent(name, details) {
// normalize details.
details.timeStamp = 0;
if (details.frameId != 0) {
- details.frameId = 1;
+ if (frameIds[details.frameId] === undefined) {
+ frameIds[details.frameId] = nextFrameId++;
+ }
+ details.frameId = frameIds[details.frameId];
}
- capturedEventData.push(["onCommitted", details]);
+ capturedEventData.push([name, details]);
checkExpectations();
+}
+
+chrome.experimental.webNavigation.onBeforeNavigate.addListener(
+ function(details) {
+ captureEvent("onBeforeNavigate", details);
+});
+
+chrome.experimental.webNavigation.onCommitted.addListener(function(details) {
+ captureEvent("onCommitted", details);
});
chrome.experimental.webNavigation.onErrorOccurred.addListener(
function(details) {
- console.log('---onErrorOccurred: ' + details.url);
- // normalize details.
- details.timeStamp = 0;
- if (details.frameId != 0) {
- details.frameId = 1;
- }
- capturedEventData.push(["onErrorOccurred", details]);
- checkExpectations();
+ captureEvent("onErrorOccurred", details);
});
var getURL = chrome.extension.getURL;
@@ -173,26 +169,26 @@ chrome.tabs.getSelected(null, function(tab) {
transitionType: "link",
url: getURL('iframe/a.html') }],
[ "onBeforeNavigate",
- { frameId: 0,
+ { frameId: 1,
requestId: 0,
tabId: tabId,
timeStamp: 0,
url: getURL('iframe/b.html') }],
[ "onCommitted",
- { frameId: 0,
+ { frameId: 1,
tabId: tabId,
timeStamp: 0,
transitionQualifiers: "",
transitionType: "auto_subframe",
url: getURL('iframe/b.html') }],
[ "onBeforeNavigate",
- { frameId: 0,
+ { frameId: 1,
requestId: 0,
tabId: tabId,
timeStamp: 0,
url: getURL('iframe/c.html') }],
[ "onCommitted",
- { frameId: 0,
+ { frameId: 1,
tabId: tabId,
timeStamp: 0,
transitionQualifiers: "",
@@ -201,6 +197,66 @@ chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.update(tabId, { url: getURL('iframe/a.html') });
},
+ /* Navigates to d.html which includes e.html and f.html as iframes. To be
+ able to predict which iframe has which id, the iframe for f.html is
+ created by javascript. f.html then navigates to g.html. */
+ function iframe2() {
+ expect([
+ [ "onBeforeNavigate",
+ { frameId: 0,
+ requestId: 0,
+ tabId: tabId,
+ timeStamp: 0,
+ url: getURL('iframe/d.html') }],
+ [ "onCommitted",
+ { frameId: 0,
+ tabId: tabId,
+ timeStamp: 0,
+ transitionQualifiers: "",
+ transitionType: "link",
+ url: getURL('iframe/d.html') }],
+ [ "onBeforeNavigate",
+ { frameId: 1,
+ requestId: 0,
+ tabId: tabId,
+ timeStamp: 0,
+ url: getURL('iframe/e.html') }],
+ [ "onCommitted",
+ { frameId: 1,
+ tabId: tabId,
+ timeStamp: 0,
+ transitionQualifiers: "",
+ transitionType: "auto_subframe",
+ url: getURL('iframe/e.html') }],
+ [ "onBeforeNavigate",
+ { frameId: 2,
+ requestId: 0,
+ tabId: tabId,
+ timeStamp: 0,
+ url: getURL('iframe/f.html') }],
+ [ "onCommitted",
+ { frameId: 2,
+ tabId: tabId,
+ timeStamp: 0,
+ transitionQualifiers: "",
+ transitionType: "auto_subframe",
+ url: getURL('iframe/f.html') }],
+ [ "onBeforeNavigate",
+ { frameId: 2,
+ requestId: 0,
+ tabId: tabId,
+ timeStamp: 0,
+ url: getURL('iframe/g.html') }],
+ [ "onCommitted",
+ { frameId: 2,
+ tabId: tabId,
+ timeStamp: 0,
+ transitionQualifiers: "",
+ transitionType: "manual_subframe",
+ url: getURL('iframe/g.html') }]]);
+ chrome.tabs.update(tabId, { url: getURL('iframe/d.html') });
+ },
+
/* Navigates to a non-existant page. */
function nonExistant() {
expect([
@@ -231,6 +287,107 @@ chrome.tabs.getSelected(null, function(tab) {
url: getURL('nonexistant.html') }]]);
chrome.tabs.update(tabId, { url: getURL('nonexistant.html') });
},
+
+ /* An page that tries to load an non-existant iframe. */
+ function nonExistantIframe() {
+ expect([
+ [ "onBeforeNavigate",
+ { frameId: 0,
+ requestId: 0,
+ tabId: tabId,
+ timeStamp: 0,
+ url: getURL('iframeFail/d.html') }],
+ [ "onCommitted",
+ { frameId: 0,
+ tabId: tabId,
+ timeStamp: 0,
+ transitionQualifiers: "",
+ transitionType: "link",
+ url: getURL('iframeFail/d.html') }],
+ [ "onBeforeNavigate",
+ { frameId: 1,
+ requestId: 0,
+ tabId: tabId,
+ timeStamp: 0,
+ url: getURL('iframeFail/c.html') }],
+ [ "onErrorOccurred",
+ { error: "net::ERR_FILE_NOT_FOUND",
+ frameId: 1,
+ tabId: tabId,
+ timeStamp: 0,
+ url: getURL('iframeFail/c.html') }],
+ [ "onBeforeNavigate",
+ { frameId: 1,
+ requestId: 0,
+ tabId: tabId,
+ timeStamp: 0,
+ url: "chrome://chromewebdata/"}],
+ [ "onCommitted",
+ { frameId: 1,
+ tabId: tabId,
+ timeStamp: 0,
+ transitionQualifiers: "",
+ transitionType: "auto_subframe",
+ url: getURL('iframeFail/c.html') }]]);
+ chrome.tabs.update(tabId, { url: getURL('iframeFail/d.html') });
+ },
+
+ /* An iframe navigates to a non-existant page. */
+ function nonExistantIframeNavigation() {
+ expect([
+ [ "onBeforeNavigate",
+ { frameId: 0,
+ requestId: 0,
+ tabId: tabId,
+ timeStamp: 0,
+ url: getURL('iframeFail/a.html') }],
+ [ "onCommitted",
+ { frameId: 0,
+ tabId: tabId,
+ timeStamp: 0,
+ transitionQualifiers: "",
+ transitionType: "link",
+ url: getURL('iframeFail/a.html') }],
+ [ "onBeforeNavigate",
+ { frameId: 1,
+ requestId: 0,
+ tabId: tabId,
+ timeStamp: 0,
+ url: getURL('iframeFail/b.html') }],
+ [ "onCommitted",
+ { frameId: 1,
+ tabId: tabId,
+ timeStamp: 0,
+ transitionQualifiers: "",
+ transitionType: "auto_subframe",
+ url: getURL('iframeFail/b.html') }],
+ [ "onBeforeNavigate",
+ { frameId: 1,
+ requestId: 0,
+ tabId: tabId,
+ timeStamp: 0,
+ url: getURL('iframeFail/c.html') }],
+ [ "onErrorOccurred",
+ { error: "net::ERR_FILE_NOT_FOUND",
+ frameId: 1,
+ tabId: tabId,
+ timeStamp: 0,
+ url: getURL('iframeFail/c.html') }],
+ [ "onBeforeNavigate",
+ { frameId: 1,
+ requestId: 0,
+ tabId: tabId,
+ timeStamp: 0,
+ url: "chrome://chromewebdata/"}],
+ [ "onCommitted",
+ { frameId: 1,
+ tabId: tabId,
+ timeStamp: 0,
+ transitionQualifiers: "",
+ transitionType: "manual_subframe",
+ url: getURL('iframeFail/c.html') }]]);
+ chrome.tabs.update(tabId, { url: getURL('iframeFail/a.html') });
+ },
]);
});
</script>