| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 event_router->BroadcastEvent(std::move(event)); | 59 event_router->BroadcastEvent(std::move(event)); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 } // namespace | 63 } // namespace |
| 64 | 64 |
| 65 // Constructs an onBeforeNavigate event. | 65 // Constructs an onBeforeNavigate event. |
| 66 std::unique_ptr<Event> CreateOnBeforeNavigateEvent( | 66 std::unique_ptr<Event> CreateOnBeforeNavigateEvent( |
| 67 content::NavigationHandle* navigation_handle) { | 67 content::NavigationHandle* navigation_handle) { |
| 68 GURL url(navigation_handle->GetURL()); | 68 GURL url(navigation_handle->GetURL()); |
| 69 if (navigation_handle->IsSrcdoc()) | |
| 70 url = GURL(content::kAboutSrcDocURL); | |
| 71 | 69 |
| 72 web_navigation::OnBeforeNavigate::Details details; | 70 web_navigation::OnBeforeNavigate::Details details; |
| 73 details.tab_id = | 71 details.tab_id = |
| 74 ExtensionTabUtil::GetTabId(navigation_handle->GetWebContents()); | 72 ExtensionTabUtil::GetTabId(navigation_handle->GetWebContents()); |
| 75 details.url = url.spec(); | 73 details.url = url.spec(); |
| 76 details.process_id = -1; | 74 details.process_id = -1; |
| 77 details.frame_id = ExtensionApiFrameIdMap::GetFrameId(navigation_handle); | 75 details.frame_id = ExtensionApiFrameIdMap::GetFrameId(navigation_handle); |
| 78 details.parent_frame_id = | 76 details.parent_frame_id = |
| 79 ExtensionApiFrameIdMap::GetParentFrameId(navigation_handle); | 77 ExtensionApiFrameIdMap::GetParentFrameId(navigation_handle); |
| 80 details.time_stamp = MilliSecondsFromTime(base::Time::Now()); | 78 details.time_stamp = MilliSecondsFromTime(base::Time::Now()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 98 // event. | 96 // event. |
| 99 void DispatchOnCommitted(events::HistogramValue histogram_value, | 97 void DispatchOnCommitted(events::HistogramValue histogram_value, |
| 100 const std::string& event_name, | 98 const std::string& event_name, |
| 101 content::NavigationHandle* navigation_handle) { | 99 content::NavigationHandle* navigation_handle) { |
| 102 content::WebContents* web_contents = navigation_handle->GetWebContents(); | 100 content::WebContents* web_contents = navigation_handle->GetWebContents(); |
| 103 GURL url(navigation_handle->GetURL()); | 101 GURL url(navigation_handle->GetURL()); |
| 104 content::RenderFrameHost* frame_host = | 102 content::RenderFrameHost* frame_host = |
| 105 navigation_handle->GetRenderFrameHost(); | 103 navigation_handle->GetRenderFrameHost(); |
| 106 ui::PageTransition transition_type = navigation_handle->GetPageTransition(); | 104 ui::PageTransition transition_type = navigation_handle->GetPageTransition(); |
| 107 | 105 |
| 108 if (navigation_handle->IsSrcdoc()) | |
| 109 url = GURL(content::kAboutSrcDocURL); | |
| 110 | |
| 111 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 106 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 112 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 107 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 113 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); | 108 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); |
| 114 dict->SetString(keys::kUrlKey, url.spec()); | 109 dict->SetString(keys::kUrlKey, url.spec()); |
| 115 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); | 110 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); |
| 116 dict->SetInteger(keys::kFrameIdKey, | 111 dict->SetInteger(keys::kFrameIdKey, |
| 117 ExtensionApiFrameIdMap::GetFrameId(frame_host)); | 112 ExtensionApiFrameIdMap::GetFrameId(frame_host)); |
| 118 | 113 |
| 119 if (navigation_handle->WasServerRedirect()) { | 114 if (navigation_handle->WasServerRedirect()) { |
| 120 transition_type = ui::PageTransitionFromInt( | 115 transition_type = ui::PageTransitionFromInt( |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 std::unique_ptr<Event> event( | 268 std::unique_ptr<Event> event( |
| 274 new Event(events::WEB_NAVIGATION_ON_TAB_REPLACED, | 269 new Event(events::WEB_NAVIGATION_ON_TAB_REPLACED, |
| 275 web_navigation::OnTabReplaced::kEventName, | 270 web_navigation::OnTabReplaced::kEventName, |
| 276 web_navigation::OnTabReplaced::Create(details))); | 271 web_navigation::OnTabReplaced::Create(details))); |
| 277 DispatchEvent(browser_context, std::move(event), GURL()); | 272 DispatchEvent(browser_context, std::move(event), GURL()); |
| 278 } | 273 } |
| 279 | 274 |
| 280 } // namespace web_navigation_api_helpers | 275 } // namespace web_navigation_api_helpers |
| 281 | 276 |
| 282 } // namespace extensions | 277 } // namespace extensions |
| OLD | NEW |