| 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 <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta
nts.h" | 15 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta
nts.h" |
| 16 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/extensions/api/web_navigation.h" | 18 #include "chrome/common/extensions/api/web_navigation.h" |
| 19 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
| 20 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
| 21 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "extensions/browser/event_router.h" | 23 #include "extensions/browser/event_router.h" |
| 24 #include "extensions/browser/extension_api_frame_id_map.h" |
| 24 #include "extensions/common/event_filtering_info.h" | 25 #include "extensions/common/event_filtering_info.h" |
| 25 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
| 26 #include "ui/base/page_transition_types.h" | 27 #include "ui/base/page_transition_types.h" |
| 27 | 28 |
| 28 namespace extensions { | 29 namespace extensions { |
| 29 | 30 |
| 30 namespace keys = web_navigation_api_constants; | 31 namespace keys = web_navigation_api_constants; |
| 31 namespace web_navigation = api::web_navigation; | 32 namespace web_navigation = api::web_navigation; |
| 32 | 33 |
| 33 namespace web_navigation_api_helpers { | 34 namespace web_navigation_api_helpers { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 55 new Event(histogram_value, event_name, std::move(args))); | 56 new Event(histogram_value, event_name, std::move(args))); |
| 56 event->restrict_to_browser_context = profile; | 57 event->restrict_to_browser_context = profile; |
| 57 event->filter_info = info; | 58 event->filter_info = info; |
| 58 event_router->BroadcastEvent(std::move(event)); | 59 event_router->BroadcastEvent(std::move(event)); |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 | 62 |
| 62 } // namespace | 63 } // namespace |
| 63 | 64 |
| 64 int GetFrameId(content::RenderFrameHost* frame_host) { | 65 int GetFrameId(content::RenderFrameHost* frame_host) { |
| 65 if (!frame_host) | 66 return ExtensionApiFrameIdMap::GetFrameId(frame_host); |
| 66 return -1; | |
| 67 return !frame_host->GetParent() ? 0 : frame_host->GetRoutingID(); | |
| 68 } | 67 } |
| 69 | 68 |
| 70 // Constructs and dispatches an onBeforeNavigate event. | 69 // Constructs and dispatches an onBeforeNavigate event. |
| 71 // TODO(dcheng): Is the parent process ID needed here? http://crbug.com/393640 | |
| 72 // Collisions are probably possible... but maybe this won't ever happen because | |
| 73 // of the SiteInstance grouping policies. | |
| 74 void DispatchOnBeforeNavigate(content::WebContents* web_contents, | 70 void DispatchOnBeforeNavigate(content::WebContents* web_contents, |
| 75 content::RenderFrameHost* frame_host, | 71 content::RenderFrameHost* frame_host, |
| 76 const GURL& validated_url) { | 72 const GURL& validated_url) { |
| 77 scoped_ptr<base::ListValue> args(new base::ListValue()); | 73 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 78 base::DictionaryValue* dict = new base::DictionaryValue(); | 74 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 79 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); | 75 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); |
| 80 dict->SetString(keys::kUrlKey, validated_url.spec()); | 76 dict->SetString(keys::kUrlKey, validated_url.spec()); |
| 81 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); | 77 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); |
| 82 dict->SetInteger(keys::kFrameIdKey, GetFrameId(frame_host)); | 78 dict->SetInteger(keys::kFrameIdKey, GetFrameId(frame_host)); |
| 83 dict->SetInteger(keys::kParentFrameIdKey, | 79 dict->SetInteger(keys::kParentFrameIdKey, |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 args->Append(dict); | 236 args->Append(dict); |
| 241 | 237 |
| 242 DispatchEvent(browser_context, events::WEB_NAVIGATION_ON_TAB_REPLACED, | 238 DispatchEvent(browser_context, events::WEB_NAVIGATION_ON_TAB_REPLACED, |
| 243 web_navigation::OnTabReplaced::kEventName, std::move(args), | 239 web_navigation::OnTabReplaced::kEventName, std::move(args), |
| 244 GURL()); | 240 GURL()); |
| 245 } | 241 } |
| 246 | 242 |
| 247 } // namespace web_navigation_api_helpers | 243 } // namespace web_navigation_api_helpers |
| 248 | 244 |
| 249 } // namespace extensions | 245 } // namespace extensions |
| OLD | NEW |