| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // Returns |time| as milliseconds since the epoch. | 43 // Returns |time| as milliseconds since the epoch. |
| 44 double MilliSecondsFromTime(const base::Time& time) { | 44 double MilliSecondsFromTime(const base::Time& time) { |
| 45 return 1000 * time.ToDoubleT(); | 45 return 1000 * time.ToDoubleT(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Dispatches events to the extension message service. | 48 // Dispatches events to the extension message service. |
| 49 void DispatchEvent(content::BrowserContext* browser_context, | 49 void DispatchEvent(content::BrowserContext* browser_context, |
| 50 std::unique_ptr<Event> event, | 50 std::unique_ptr<Event> event, |
| 51 const GURL& url) { | 51 const GURL& url) { |
| 52 EventFilteringInfo info; | 52 EventFilteringInfo info; |
| 53 info.SetURL(url); | 53 info.url = url; |
| 54 | 54 |
| 55 Profile* profile = Profile::FromBrowserContext(browser_context); | 55 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 56 EventRouter* event_router = EventRouter::Get(profile); | 56 EventRouter* event_router = EventRouter::Get(profile); |
| 57 if (profile && event_router) { | 57 if (profile && event_router) { |
| 58 DCHECK_EQ(profile, event->restrict_to_browser_context); | 58 DCHECK_EQ(profile, event->restrict_to_browser_context); |
| 59 event->filter_info = info; | 59 event->filter_info = info; |
| 60 event_router->BroadcastEvent(std::move(event)); | 60 event_router->BroadcastEvent(std::move(event)); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 78 ExtensionApiFrameIdMap::GetParentFrameId(navigation_handle); | 78 ExtensionApiFrameIdMap::GetParentFrameId(navigation_handle); |
| 79 details.time_stamp = MilliSecondsFromTime(base::Time::Now()); | 79 details.time_stamp = MilliSecondsFromTime(base::Time::Now()); |
| 80 | 80 |
| 81 auto event = base::MakeUnique<Event>( | 81 auto event = base::MakeUnique<Event>( |
| 82 events::WEB_NAVIGATION_ON_BEFORE_NAVIGATE, | 82 events::WEB_NAVIGATION_ON_BEFORE_NAVIGATE, |
| 83 web_navigation::OnBeforeNavigate::kEventName, | 83 web_navigation::OnBeforeNavigate::kEventName, |
| 84 web_navigation::OnBeforeNavigate::Create(details), | 84 web_navigation::OnBeforeNavigate::Create(details), |
| 85 navigation_handle->GetWebContents()->GetBrowserContext()); | 85 navigation_handle->GetWebContents()->GetBrowserContext()); |
| 86 | 86 |
| 87 EventFilteringInfo info; | 87 EventFilteringInfo info; |
| 88 info.SetURL(navigation_handle->GetURL()); | 88 info.url = navigation_handle->GetURL(); |
| 89 event->filter_info = info; | 89 event->filter_info = info; |
| 90 | 90 |
| 91 return event; | 91 return event; |
| 92 } | 92 } |
| 93 | 93 |
| 94 // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated | 94 // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated |
| 95 // event. | 95 // event. |
| 96 void DispatchOnCommitted(events::HistogramValue histogram_value, | 96 void DispatchOnCommitted(events::HistogramValue histogram_value, |
| 97 const std::string& event_name, | 97 const std::string& event_name, |
| 98 content::NavigationHandle* navigation_handle) { | 98 content::NavigationHandle* navigation_handle) { |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 auto event = base::MakeUnique<Event>( | 274 auto event = base::MakeUnique<Event>( |
| 275 events::WEB_NAVIGATION_ON_TAB_REPLACED, | 275 events::WEB_NAVIGATION_ON_TAB_REPLACED, |
| 276 web_navigation::OnTabReplaced::kEventName, | 276 web_navigation::OnTabReplaced::kEventName, |
| 277 web_navigation::OnTabReplaced::Create(details), browser_context); | 277 web_navigation::OnTabReplaced::Create(details), browser_context); |
| 278 DispatchEvent(browser_context, std::move(event), GURL()); | 278 DispatchEvent(browser_context, std::move(event), GURL()); |
| 279 } | 279 } |
| 280 | 280 |
| 281 } // namespace web_navigation_api_helpers | 281 } // namespace web_navigation_api_helpers |
| 282 | 282 |
| 283 } // namespace extensions | 283 } // namespace extensions |
| OLD | NEW |