| 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 "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta
nts.h" | 13 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta
nts.h" |
| 14 #include "chrome/browser/extensions/extension_tab_util.h" | 14 #include "chrome/browser/extensions/extension_tab_util.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/extensions/api/web_navigation.h" | 16 #include "chrome/common/extensions/api/web_navigation.h" |
| 17 #include "content/public/browser/render_frame_host.h" | 17 #include "content/public/browser/render_frame_host.h" |
| 18 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
| 19 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
| 20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/common/page_transition_types.h" | |
| 22 #include "extensions/browser/event_router.h" | 21 #include "extensions/browser/event_router.h" |
| 23 #include "extensions/common/event_filtering_info.h" | 22 #include "extensions/common/event_filtering_info.h" |
| 24 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 24 #include "ui/base/page_transition_types.h" |
| 25 | 25 |
| 26 namespace extensions { | 26 namespace extensions { |
| 27 | 27 |
| 28 namespace keys = web_navigation_api_constants; | 28 namespace keys = web_navigation_api_constants; |
| 29 namespace web_navigation = api::web_navigation; | 29 namespace web_navigation = api::web_navigation; |
| 30 | 30 |
| 31 namespace web_navigation_api_helpers { | 31 namespace web_navigation_api_helpers { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 args.Pass(), | 86 args.Pass(), |
| 87 validated_url); | 87 validated_url); |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated | 90 // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated |
| 91 // event. | 91 // event. |
| 92 void DispatchOnCommitted(const std::string& event_name, | 92 void DispatchOnCommitted(const std::string& event_name, |
| 93 content::WebContents* web_contents, | 93 content::WebContents* web_contents, |
| 94 content::RenderFrameHost* frame_host, | 94 content::RenderFrameHost* frame_host, |
| 95 const GURL& url, | 95 const GURL& url, |
| 96 content::PageTransition transition_type) { | 96 ui::PageTransition transition_type) { |
| 97 scoped_ptr<base::ListValue> args(new base::ListValue()); | 97 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 98 base::DictionaryValue* dict = new base::DictionaryValue(); | 98 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 99 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); | 99 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); |
| 100 dict->SetString(keys::kUrlKey, url.spec()); | 100 dict->SetString(keys::kUrlKey, url.spec()); |
| 101 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); | 101 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); |
| 102 dict->SetInteger(keys::kFrameIdKey, GetFrameId(frame_host)); | 102 dict->SetInteger(keys::kFrameIdKey, GetFrameId(frame_host)); |
| 103 std::string transition_type_string = | 103 std::string transition_type_string = |
| 104 content::PageTransitionGetCoreTransitionString(transition_type); | 104 ui::PageTransitionGetCoreTransitionString(transition_type); |
| 105 // For webNavigation API backward compatibility, keep "start_page" even after | 105 // For webNavigation API backward compatibility, keep "start_page" even after |
| 106 // renamed to "auto_toplevel". | 106 // renamed to "auto_toplevel". |
| 107 if (PageTransitionStripQualifier(transition_type) == | 107 if (ui::PageTransitionStripQualifier(transition_type) == |
| 108 content::PAGE_TRANSITION_AUTO_TOPLEVEL) | 108 ui::PAGE_TRANSITION_AUTO_TOPLEVEL) |
| 109 transition_type_string = "start_page"; | 109 transition_type_string = "start_page"; |
| 110 dict->SetString(keys::kTransitionTypeKey, transition_type_string); | 110 dict->SetString(keys::kTransitionTypeKey, transition_type_string); |
| 111 base::ListValue* qualifiers = new base::ListValue(); | 111 base::ListValue* qualifiers = new base::ListValue(); |
| 112 if (transition_type & content::PAGE_TRANSITION_CLIENT_REDIRECT) | 112 if (transition_type & ui::PAGE_TRANSITION_CLIENT_REDIRECT) |
| 113 qualifiers->Append(new base::StringValue("client_redirect")); | 113 qualifiers->Append(new base::StringValue("client_redirect")); |
| 114 if (transition_type & content::PAGE_TRANSITION_SERVER_REDIRECT) | 114 if (transition_type & ui::PAGE_TRANSITION_SERVER_REDIRECT) |
| 115 qualifiers->Append(new base::StringValue("server_redirect")); | 115 qualifiers->Append(new base::StringValue("server_redirect")); |
| 116 if (transition_type & content::PAGE_TRANSITION_FORWARD_BACK) | 116 if (transition_type & ui::PAGE_TRANSITION_FORWARD_BACK) |
| 117 qualifiers->Append(new base::StringValue("forward_back")); | 117 qualifiers->Append(new base::StringValue("forward_back")); |
| 118 if (transition_type & content::PAGE_TRANSITION_FROM_ADDRESS_BAR) | 118 if (transition_type & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) |
| 119 qualifiers->Append(new base::StringValue("from_address_bar")); | 119 qualifiers->Append(new base::StringValue("from_address_bar")); |
| 120 dict->Set(keys::kTransitionQualifiersKey, qualifiers); | 120 dict->Set(keys::kTransitionQualifiersKey, qualifiers); |
| 121 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); | 121 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
| 122 args->Append(dict); | 122 args->Append(dict); |
| 123 | 123 |
| 124 DispatchEvent(web_contents->GetBrowserContext(), event_name, args.Pass(), | 124 DispatchEvent(web_contents->GetBrowserContext(), event_name, args.Pass(), |
| 125 url); | 125 url); |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Constructs and dispatches an onDOMContentLoaded event. | 128 // Constructs and dispatches an onDOMContentLoaded event. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 235 |
| 236 DispatchEvent(browser_context, | 236 DispatchEvent(browser_context, |
| 237 web_navigation::OnTabReplaced::kEventName, | 237 web_navigation::OnTabReplaced::kEventName, |
| 238 args.Pass(), | 238 args.Pass(), |
| 239 GURL()); | 239 GURL()); |
| 240 } | 240 } |
| 241 | 241 |
| 242 } // namespace web_navigation_api_helpers | 242 } // namespace web_navigation_api_helpers |
| 243 | 243 |
| 244 } // namespace extensions | 244 } // namespace extensions |
| OLD | NEW |