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 <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 event->filter_info = info; | 57 event->filter_info = info; |
58 event_router->BroadcastEvent(std::move(event)); | 58 event_router->BroadcastEvent(std::move(event)); |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 } // namespace | 62 } // namespace |
63 | 63 |
64 // Constructs and dispatches an onBeforeNavigate event. | 64 // Constructs and dispatches an onBeforeNavigate event. |
65 void DispatchOnBeforeNavigate(content::NavigationHandle* navigation_handle) { | 65 void DispatchOnBeforeNavigate(content::NavigationHandle* navigation_handle) { |
66 GURL url(navigation_handle->GetURL()); | 66 GURL url(navigation_handle->GetURL()); |
67 if (navigation_handle->IsSrcdoc()) | |
68 url = GURL(content::kAboutSrcDocURL); | |
69 | 67 |
70 web_navigation::OnBeforeNavigate::Details details; | 68 web_navigation::OnBeforeNavigate::Details details; |
71 details.tab_id = | 69 details.tab_id = |
72 ExtensionTabUtil::GetTabId(navigation_handle->GetWebContents()); | 70 ExtensionTabUtil::GetTabId(navigation_handle->GetWebContents()); |
73 details.url = url.spec(); | 71 details.url = url.spec(); |
74 details.process_id = -1; | 72 details.process_id = -1; |
75 details.frame_id = ExtensionApiFrameIdMap::GetFrameId(navigation_handle); | 73 details.frame_id = ExtensionApiFrameIdMap::GetFrameId(navigation_handle); |
76 details.parent_frame_id = | 74 details.parent_frame_id = |
77 ExtensionApiFrameIdMap::GetParentFrameId(navigation_handle); | 75 ExtensionApiFrameIdMap::GetParentFrameId(navigation_handle); |
78 details.time_stamp = MilliSecondsFromTime(base::Time::Now()); | 76 details.time_stamp = MilliSecondsFromTime(base::Time::Now()); |
(...skipping 10 matching lines...) Expand all Loading... |
89 // event. | 87 // event. |
90 void DispatchOnCommitted(events::HistogramValue histogram_value, | 88 void DispatchOnCommitted(events::HistogramValue histogram_value, |
91 const std::string& event_name, | 89 const std::string& event_name, |
92 content::NavigationHandle* navigation_handle) { | 90 content::NavigationHandle* navigation_handle) { |
93 content::WebContents* web_contents = navigation_handle->GetWebContents(); | 91 content::WebContents* web_contents = navigation_handle->GetWebContents(); |
94 GURL url(navigation_handle->GetURL()); | 92 GURL url(navigation_handle->GetURL()); |
95 content::RenderFrameHost* frame_host = | 93 content::RenderFrameHost* frame_host = |
96 navigation_handle->GetRenderFrameHost(); | 94 navigation_handle->GetRenderFrameHost(); |
97 ui::PageTransition transition_type = navigation_handle->GetPageTransition(); | 95 ui::PageTransition transition_type = navigation_handle->GetPageTransition(); |
98 | 96 |
99 if (navigation_handle->IsSrcdoc()) | |
100 url = GURL(content::kAboutSrcDocURL); | |
101 | |
102 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 97 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
103 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 98 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
104 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); | 99 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); |
105 dict->SetString(keys::kUrlKey, url.spec()); | 100 dict->SetString(keys::kUrlKey, url.spec()); |
106 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); | 101 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); |
107 dict->SetInteger(keys::kFrameIdKey, | 102 dict->SetInteger(keys::kFrameIdKey, |
108 ExtensionApiFrameIdMap::GetFrameId(frame_host)); | 103 ExtensionApiFrameIdMap::GetFrameId(frame_host)); |
109 | 104 |
110 if (navigation_handle->WasServerRedirect()) { | 105 if (navigation_handle->WasServerRedirect()) { |
111 transition_type = ui::PageTransitionFromInt( | 106 transition_type = ui::PageTransitionFromInt( |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 std::unique_ptr<Event> event( | 253 std::unique_ptr<Event> event( |
259 new Event(events::WEB_NAVIGATION_ON_TAB_REPLACED, | 254 new Event(events::WEB_NAVIGATION_ON_TAB_REPLACED, |
260 web_navigation::OnTabReplaced::kEventName, | 255 web_navigation::OnTabReplaced::kEventName, |
261 web_navigation::OnTabReplaced::Create(details))); | 256 web_navigation::OnTabReplaced::Create(details))); |
262 DispatchEvent(browser_context, std::move(event), GURL()); | 257 DispatchEvent(browser_context, std::move(event), GURL()); |
263 } | 258 } |
264 | 259 |
265 } // namespace web_navigation_api_helpers | 260 } // namespace web_navigation_api_helpers |
266 | 261 |
267 } // namespace extensions | 262 } // namespace extensions |
OLD | NEW |