| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Implements the Chrome Extensions WebNavigation API. | 5 // Implements the Chrome Extensions WebNavigation API. |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper
s.h" | 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper
s.h" |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta
nts.h" | 13 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta
nts.h" |
| 14 #include "chrome/browser/extensions/extension_tab_util.h" | 14 #include "chrome/browser/extensions/extension_tab_util.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/extensions/api/web_navigation.h" | 16 #include "chrome/common/extensions/api/web_navigation.h" |
| 17 #include "content/public/browser/render_frame_host.h" | 17 #include "content/public/browser/render_frame_host.h" |
| 18 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
| 19 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
| 20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #include "extensions/browser/event_router.h" | 21 #include "extensions/browser/event_router.h" |
| 22 #include "extensions/browser/extension_api_frame_id_map.h" |
| 22 #include "extensions/common/event_filtering_info.h" | 23 #include "extensions/common/event_filtering_info.h" |
| 23 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 24 #include "ui/base/page_transition_types.h" | 25 #include "ui/base/page_transition_types.h" |
| 25 | 26 |
| 26 namespace extensions { | 27 namespace extensions { |
| 27 | 28 |
| 28 namespace keys = web_navigation_api_constants; | 29 namespace keys = web_navigation_api_constants; |
| 29 namespace web_navigation = api::web_navigation; | 30 namespace web_navigation = api::web_navigation; |
| 30 | 31 |
| 31 namespace web_navigation_api_helpers { | 32 namespace web_navigation_api_helpers { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 53 new Event(histogram_value, event_name, args.Pass())); | 54 new Event(histogram_value, event_name, args.Pass())); |
| 54 event->restrict_to_browser_context = profile; | 55 event->restrict_to_browser_context = profile; |
| 55 event->filter_info = info; | 56 event->filter_info = info; |
| 56 event_router->BroadcastEvent(event.Pass()); | 57 event_router->BroadcastEvent(event.Pass()); |
| 57 } | 58 } |
| 58 } | 59 } |
| 59 | 60 |
| 60 } // namespace | 61 } // namespace |
| 61 | 62 |
| 62 int GetFrameId(content::RenderFrameHost* frame_host) { | 63 int GetFrameId(content::RenderFrameHost* frame_host) { |
| 63 if (!frame_host) | 64 return ExtensionApiFrameIdMap::Get()->GetFrameId(frame_host).frame_id; |
| 64 return -1; | |
| 65 return !frame_host->GetParent() ? 0 : frame_host->GetRoutingID(); | |
| 66 } | 65 } |
| 67 | 66 |
| 68 // Constructs and dispatches an onBeforeNavigate event. | 67 // Constructs and dispatches an onBeforeNavigate event. |
| 69 // TODO(dcheng): Is the parent process ID needed here? http://crbug.com/393640 | |
| 70 // Collisions are probably possible... but maybe this won't ever happen because | |
| 71 // of the SiteInstance grouping policies. | |
| 72 void DispatchOnBeforeNavigate(content::WebContents* web_contents, | 68 void DispatchOnBeforeNavigate(content::WebContents* web_contents, |
| 73 content::RenderFrameHost* frame_host, | 69 content::RenderFrameHost* frame_host, |
| 74 const GURL& validated_url) { | 70 const GURL& validated_url) { |
| 75 scoped_ptr<base::ListValue> args(new base::ListValue()); | 71 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 76 base::DictionaryValue* dict = new base::DictionaryValue(); | 72 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 77 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); | 73 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); |
| 78 dict->SetString(keys::kUrlKey, validated_url.spec()); | 74 dict->SetString(keys::kUrlKey, validated_url.spec()); |
| 79 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); | 75 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); |
| 80 dict->SetInteger(keys::kFrameIdKey, GetFrameId(frame_host)); | 76 dict->SetInteger(keys::kFrameIdKey, GetFrameId(frame_host)); |
| 81 dict->SetInteger(keys::kParentFrameIdKey, | 77 dict->SetInteger(keys::kParentFrameIdKey, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); | 232 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
| 237 args->Append(dict); | 233 args->Append(dict); |
| 238 | 234 |
| 239 DispatchEvent(browser_context, events::WEB_NAVIGATION_ON_TAB_REPLACED, | 235 DispatchEvent(browser_context, events::WEB_NAVIGATION_ON_TAB_REPLACED, |
| 240 web_navigation::OnTabReplaced::kEventName, args.Pass(), GURL()); | 236 web_navigation::OnTabReplaced::kEventName, args.Pass(), GURL()); |
| 241 } | 237 } |
| 242 | 238 |
| 243 } // namespace web_navigation_api_helpers | 239 } // namespace web_navigation_api_helpers |
| 244 | 240 |
| 245 } // namespace extensions | 241 } // namespace extensions |
| OLD | NEW |