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 <utility> | 10 #include <utility> |
10 | 11 |
11 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta
nts.h" | 16 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta
nts.h" |
16 #include "chrome/browser/extensions/extension_tab_util.h" | 17 #include "chrome/browser/extensions/extension_tab_util.h" |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/extensions/api/web_navigation.h" | 19 #include "chrome/common/extensions/api/web_navigation.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 content::WebContents* web_contents = navigation_handle->GetWebContents(); | 93 content::WebContents* web_contents = navigation_handle->GetWebContents(); |
93 GURL url(navigation_handle->GetURL()); | 94 GURL url(navigation_handle->GetURL()); |
94 content::RenderFrameHost* frame_host = | 95 content::RenderFrameHost* frame_host = |
95 navigation_handle->GetRenderFrameHost(); | 96 navigation_handle->GetRenderFrameHost(); |
96 ui::PageTransition transition_type = navigation_handle->GetPageTransition(); | 97 ui::PageTransition transition_type = navigation_handle->GetPageTransition(); |
97 | 98 |
98 if (navigation_handle->IsSrcdoc()) | 99 if (navigation_handle->IsSrcdoc()) |
99 url = GURL(content::kAboutSrcDocURL); | 100 url = GURL(content::kAboutSrcDocURL); |
100 | 101 |
101 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 102 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
102 base::DictionaryValue* dict = new base::DictionaryValue(); | 103 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
103 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); | 104 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); |
104 dict->SetString(keys::kUrlKey, url.spec()); | 105 dict->SetString(keys::kUrlKey, url.spec()); |
105 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); | 106 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); |
106 dict->SetInteger(keys::kFrameIdKey, | 107 dict->SetInteger(keys::kFrameIdKey, |
107 ExtensionApiFrameIdMap::GetFrameId(frame_host)); | 108 ExtensionApiFrameIdMap::GetFrameId(frame_host)); |
108 | 109 |
109 if (navigation_handle->WasServerRedirect()) { | 110 if (navigation_handle->WasServerRedirect()) { |
110 transition_type = ui::PageTransitionFromInt( | 111 transition_type = ui::PageTransitionFromInt( |
111 transition_type | ui::PAGE_TRANSITION_SERVER_REDIRECT); | 112 transition_type | ui::PAGE_TRANSITION_SERVER_REDIRECT); |
112 } | 113 } |
(...skipping 10 matching lines...) Expand all Loading... |
123 if (transition_type & ui::PAGE_TRANSITION_CLIENT_REDIRECT) | 124 if (transition_type & ui::PAGE_TRANSITION_CLIENT_REDIRECT) |
124 qualifiers->AppendString("client_redirect"); | 125 qualifiers->AppendString("client_redirect"); |
125 if (transition_type & ui::PAGE_TRANSITION_SERVER_REDIRECT) | 126 if (transition_type & ui::PAGE_TRANSITION_SERVER_REDIRECT) |
126 qualifiers->AppendString("server_redirect"); | 127 qualifiers->AppendString("server_redirect"); |
127 if (transition_type & ui::PAGE_TRANSITION_FORWARD_BACK) | 128 if (transition_type & ui::PAGE_TRANSITION_FORWARD_BACK) |
128 qualifiers->AppendString("forward_back"); | 129 qualifiers->AppendString("forward_back"); |
129 if (transition_type & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) | 130 if (transition_type & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) |
130 qualifiers->AppendString("from_address_bar"); | 131 qualifiers->AppendString("from_address_bar"); |
131 dict->Set(keys::kTransitionQualifiersKey, qualifiers); | 132 dict->Set(keys::kTransitionQualifiersKey, qualifiers); |
132 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); | 133 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
133 args->Append(dict); | 134 args->Append(std::move(dict)); |
134 | 135 |
135 std::unique_ptr<Event> event( | 136 std::unique_ptr<Event> event( |
136 new Event(histogram_value, event_name, std::move(args))); | 137 new Event(histogram_value, event_name, std::move(args))); |
137 DispatchEvent(navigation_handle->GetWebContents()->GetBrowserContext(), | 138 DispatchEvent(navigation_handle->GetWebContents()->GetBrowserContext(), |
138 std::move(event), url); | 139 std::move(event), url); |
139 } | 140 } |
140 | 141 |
141 // Constructs and dispatches an onDOMContentLoaded event. | 142 // Constructs and dispatches an onDOMContentLoaded event. |
142 void DispatchOnDOMContentLoaded(content::WebContents* web_contents, | 143 void DispatchOnDOMContentLoaded(content::WebContents* web_contents, |
143 content::RenderFrameHost* frame_host, | 144 content::RenderFrameHost* frame_host, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 std::unique_ptr<Event> event( | 258 std::unique_ptr<Event> event( |
258 new Event(events::WEB_NAVIGATION_ON_TAB_REPLACED, | 259 new Event(events::WEB_NAVIGATION_ON_TAB_REPLACED, |
259 web_navigation::OnTabReplaced::kEventName, | 260 web_navigation::OnTabReplaced::kEventName, |
260 web_navigation::OnTabReplaced::Create(details))); | 261 web_navigation::OnTabReplaced::Create(details))); |
261 DispatchEvent(browser_context, std::move(event), GURL()); | 262 DispatchEvent(browser_context, std::move(event), GURL()); |
262 } | 263 } |
263 | 264 |
264 } // namespace web_navigation_api_helpers | 265 } // namespace web_navigation_api_helpers |
265 | 266 |
266 } // namespace extensions | 267 } // namespace extensions |
OLD | NEW |