| 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> |
| 11 | 11 |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/memory/ptr_util.h" | |
| 14 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 16 #include "base/values.h" | 15 #include "base/values.h" |
| 17 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" | 16 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" |
| 18 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta
nts.h" | 17 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta
nts.h" |
| 19 #include "chrome/browser/extensions/extension_tab_util.h" | 18 #include "chrome/browser/extensions/extension_tab_util.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/extensions/api/web_navigation.h" | 20 #include "chrome/common/extensions/api/web_navigation.h" |
| 22 #include "content/public/browser/navigation_handle.h" | 21 #include "content/public/browser/navigation_handle.h" |
| 23 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 117 } |
| 119 | 118 |
| 120 std::string transition_type_string = | 119 std::string transition_type_string = |
| 121 ui::PageTransitionGetCoreTransitionString(transition_type); | 120 ui::PageTransitionGetCoreTransitionString(transition_type); |
| 122 // For webNavigation API backward compatibility, keep "start_page" even after | 121 // For webNavigation API backward compatibility, keep "start_page" even after |
| 123 // renamed to "auto_toplevel". | 122 // renamed to "auto_toplevel". |
| 124 if (ui::PageTransitionCoreTypeIs(transition_type, | 123 if (ui::PageTransitionCoreTypeIs(transition_type, |
| 125 ui::PAGE_TRANSITION_AUTO_TOPLEVEL)) | 124 ui::PAGE_TRANSITION_AUTO_TOPLEVEL)) |
| 126 transition_type_string = "start_page"; | 125 transition_type_string = "start_page"; |
| 127 dict->SetString(keys::kTransitionTypeKey, transition_type_string); | 126 dict->SetString(keys::kTransitionTypeKey, transition_type_string); |
| 128 auto qualifiers = base::MakeUnique<base::ListValue>(); | 127 base::ListValue* qualifiers = new base::ListValue(); |
| 129 if (transition_type & ui::PAGE_TRANSITION_CLIENT_REDIRECT) | 128 if (transition_type & ui::PAGE_TRANSITION_CLIENT_REDIRECT) |
| 130 qualifiers->AppendString("client_redirect"); | 129 qualifiers->AppendString("client_redirect"); |
| 131 if (transition_type & ui::PAGE_TRANSITION_SERVER_REDIRECT) | 130 if (transition_type & ui::PAGE_TRANSITION_SERVER_REDIRECT) |
| 132 qualifiers->AppendString("server_redirect"); | 131 qualifiers->AppendString("server_redirect"); |
| 133 if (transition_type & ui::PAGE_TRANSITION_FORWARD_BACK) | 132 if (transition_type & ui::PAGE_TRANSITION_FORWARD_BACK) |
| 134 qualifiers->AppendString("forward_back"); | 133 qualifiers->AppendString("forward_back"); |
| 135 if (transition_type & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) | 134 if (transition_type & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) |
| 136 qualifiers->AppendString("from_address_bar"); | 135 qualifiers->AppendString("from_address_bar"); |
| 137 dict->Set(keys::kTransitionQualifiersKey, std::move(qualifiers)); | 136 dict->Set(keys::kTransitionQualifiersKey, qualifiers); |
| 138 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); | 137 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
| 139 args->Append(std::move(dict)); | 138 args->Append(std::move(dict)); |
| 140 | 139 |
| 141 std::unique_ptr<Event> event( | 140 std::unique_ptr<Event> event( |
| 142 new Event(histogram_value, event_name, std::move(args))); | 141 new Event(histogram_value, event_name, std::move(args))); |
| 143 DispatchEvent(navigation_handle->GetWebContents()->GetBrowserContext(), | 142 DispatchEvent(navigation_handle->GetWebContents()->GetBrowserContext(), |
| 144 std::move(event), url); | 143 std::move(event), url); |
| 145 } | 144 } |
| 146 | 145 |
| 147 // Constructs and dispatches an onDOMContentLoaded event. | 146 // Constructs and dispatches an onDOMContentLoaded event. |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 std::unique_ptr<Event> event( | 268 std::unique_ptr<Event> event( |
| 270 new Event(events::WEB_NAVIGATION_ON_TAB_REPLACED, | 269 new Event(events::WEB_NAVIGATION_ON_TAB_REPLACED, |
| 271 web_navigation::OnTabReplaced::kEventName, | 270 web_navigation::OnTabReplaced::kEventName, |
| 272 web_navigation::OnTabReplaced::Create(details))); | 271 web_navigation::OnTabReplaced::Create(details))); |
| 273 DispatchEvent(browser_context, std::move(event), GURL()); | 272 DispatchEvent(browser_context, std::move(event), GURL()); |
| 274 } | 273 } |
| 275 | 274 |
| 276 } // namespace web_navigation_api_helpers | 275 } // namespace web_navigation_api_helpers |
| 277 | 276 |
| 278 } // namespace extensions | 277 } // namespace extensions |
| OLD | NEW |