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/extension_webnavigation_api.h" | 7 #include "chrome/browser/extensions/extension_webnavigation_api.h" |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 const GURL& validated_url) { | 82 const GURL& validated_url) { |
83 ListValue args; | 83 ListValue args; |
84 DictionaryValue* dict = new DictionaryValue(); | 84 DictionaryValue* dict = new DictionaryValue(); |
85 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); | 85 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); |
86 dict->SetString(keys::kUrlKey, validated_url.spec()); | 86 dict->SetString(keys::kUrlKey, validated_url.spec()); |
87 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); | 87 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); |
88 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); | 88 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
89 args.Append(dict); | 89 args.Append(dict); |
90 | 90 |
91 std::string json_args; | 91 std::string json_args; |
92 base::JSONWriter::Write(&args, false, &json_args); | 92 base::JSONWriter::Write(&args, &json_args); |
93 DispatchEvent(web_contents->GetBrowserContext(), | 93 DispatchEvent(web_contents->GetBrowserContext(), |
94 keys::kOnBeforeNavigate, | 94 keys::kOnBeforeNavigate, |
95 json_args); | 95 json_args); |
96 } | 96 } |
97 | 97 |
98 // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated | 98 // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated |
99 // event. | 99 // event. |
100 void DispatchOnCommitted(const char* event_name, | 100 void DispatchOnCommitted(const char* event_name, |
101 WebContents* web_contents, | 101 WebContents* web_contents, |
102 int64 frame_id, | 102 int64 frame_id, |
(...skipping 15 matching lines...) Expand all Loading... |
118 qualifiers->Append(Value::CreateStringValue("server_redirect")); | 118 qualifiers->Append(Value::CreateStringValue("server_redirect")); |
119 if (transition_type & content::PAGE_TRANSITION_FORWARD_BACK) | 119 if (transition_type & content::PAGE_TRANSITION_FORWARD_BACK) |
120 qualifiers->Append(Value::CreateStringValue("forward_back")); | 120 qualifiers->Append(Value::CreateStringValue("forward_back")); |
121 if (transition_type & content::PAGE_TRANSITION_FROM_ADDRESS_BAR) | 121 if (transition_type & content::PAGE_TRANSITION_FROM_ADDRESS_BAR) |
122 qualifiers->Append(Value::CreateStringValue("from_address_bar")); | 122 qualifiers->Append(Value::CreateStringValue("from_address_bar")); |
123 dict->Set(keys::kTransitionQualifiersKey, qualifiers); | 123 dict->Set(keys::kTransitionQualifiersKey, qualifiers); |
124 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); | 124 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
125 args.Append(dict); | 125 args.Append(dict); |
126 | 126 |
127 std::string json_args; | 127 std::string json_args; |
128 base::JSONWriter::Write(&args, false, &json_args); | 128 base::JSONWriter::Write(&args, &json_args); |
129 DispatchEvent(web_contents->GetBrowserContext(), event_name, json_args); | 129 DispatchEvent(web_contents->GetBrowserContext(), event_name, json_args); |
130 } | 130 } |
131 | 131 |
132 // Constructs and dispatches an onDOMContentLoaded event. | 132 // Constructs and dispatches an onDOMContentLoaded event. |
133 void DispatchOnDOMContentLoaded(WebContents* web_contents, | 133 void DispatchOnDOMContentLoaded(WebContents* web_contents, |
134 const GURL& url, | 134 const GURL& url, |
135 bool is_main_frame, | 135 bool is_main_frame, |
136 int64 frame_id) { | 136 int64 frame_id) { |
137 ListValue args; | 137 ListValue args; |
138 DictionaryValue* dict = new DictionaryValue(); | 138 DictionaryValue* dict = new DictionaryValue(); |
139 dict->SetInteger(keys::kTabIdKey, | 139 dict->SetInteger(keys::kTabIdKey, |
140 ExtensionTabUtil::GetTabId(web_contents)); | 140 ExtensionTabUtil::GetTabId(web_contents)); |
141 dict->SetString(keys::kUrlKey, url.spec()); | 141 dict->SetString(keys::kUrlKey, url.spec()); |
142 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); | 142 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); |
143 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); | 143 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
144 args.Append(dict); | 144 args.Append(dict); |
145 | 145 |
146 std::string json_args; | 146 std::string json_args; |
147 base::JSONWriter::Write(&args, false, &json_args); | 147 base::JSONWriter::Write(&args, &json_args); |
148 DispatchEvent(web_contents->GetBrowserContext(), | 148 DispatchEvent(web_contents->GetBrowserContext(), |
149 keys::kOnDOMContentLoaded, | 149 keys::kOnDOMContentLoaded, |
150 json_args); | 150 json_args); |
151 } | 151 } |
152 | 152 |
153 // Constructs and dispatches an onCompleted event. | 153 // Constructs and dispatches an onCompleted event. |
154 void DispatchOnCompleted(WebContents* web_contents, | 154 void DispatchOnCompleted(WebContents* web_contents, |
155 const GURL& url, | 155 const GURL& url, |
156 bool is_main_frame, | 156 bool is_main_frame, |
157 int64 frame_id) { | 157 int64 frame_id) { |
158 ListValue args; | 158 ListValue args; |
159 DictionaryValue* dict = new DictionaryValue(); | 159 DictionaryValue* dict = new DictionaryValue(); |
160 dict->SetInteger(keys::kTabIdKey, | 160 dict->SetInteger(keys::kTabIdKey, |
161 ExtensionTabUtil::GetTabId(web_contents)); | 161 ExtensionTabUtil::GetTabId(web_contents)); |
162 dict->SetString(keys::kUrlKey, url.spec()); | 162 dict->SetString(keys::kUrlKey, url.spec()); |
163 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); | 163 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); |
164 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); | 164 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
165 args.Append(dict); | 165 args.Append(dict); |
166 | 166 |
167 std::string json_args; | 167 std::string json_args; |
168 base::JSONWriter::Write(&args, false, &json_args); | 168 base::JSONWriter::Write(&args, &json_args); |
169 DispatchEvent(web_contents->GetBrowserContext(), | 169 DispatchEvent(web_contents->GetBrowserContext(), |
170 keys::kOnCompleted, json_args); | 170 keys::kOnCompleted, json_args); |
171 } | 171 } |
172 | 172 |
173 // Constructs and dispatches an onCreatedNavigationTarget event. | 173 // Constructs and dispatches an onCreatedNavigationTarget event. |
174 void DispatchOnCreatedNavigationTarget( | 174 void DispatchOnCreatedNavigationTarget( |
175 WebContents* web_contents, | 175 WebContents* web_contents, |
176 BrowserContext* browser_context, | 176 BrowserContext* browser_context, |
177 int64 source_frame_id, | 177 int64 source_frame_id, |
178 bool source_frame_is_main_frame, | 178 bool source_frame_is_main_frame, |
(...skipping 12 matching lines...) Expand all Loading... |
191 ExtensionTabUtil::GetTabId(web_contents)); | 191 ExtensionTabUtil::GetTabId(web_contents)); |
192 dict->SetInteger(keys::kSourceFrameIdKey, | 192 dict->SetInteger(keys::kSourceFrameIdKey, |
193 GetFrameId(source_frame_is_main_frame, source_frame_id)); | 193 GetFrameId(source_frame_is_main_frame, source_frame_id)); |
194 dict->SetString(keys::kUrlKey, target_url.possibly_invalid_spec()); | 194 dict->SetString(keys::kUrlKey, target_url.possibly_invalid_spec()); |
195 dict->SetInteger(keys::kTabIdKey, | 195 dict->SetInteger(keys::kTabIdKey, |
196 ExtensionTabUtil::GetTabId(target_web_contents)); | 196 ExtensionTabUtil::GetTabId(target_web_contents)); |
197 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); | 197 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
198 args.Append(dict); | 198 args.Append(dict); |
199 | 199 |
200 std::string json_args; | 200 std::string json_args; |
201 base::JSONWriter::Write(&args, false, &json_args); | 201 base::JSONWriter::Write(&args, &json_args); |
202 DispatchEvent( | 202 DispatchEvent( |
203 browser_context, keys::kOnCreatedNavigationTarget, json_args); | 203 browser_context, keys::kOnCreatedNavigationTarget, json_args); |
204 } | 204 } |
205 | 205 |
206 // Constructs and dispatches an onErrorOccurred event. | 206 // Constructs and dispatches an onErrorOccurred event. |
207 void DispatchOnErrorOccurred(WebContents* web_contents, | 207 void DispatchOnErrorOccurred(WebContents* web_contents, |
208 const GURL& url, | 208 const GURL& url, |
209 int64 frame_id, | 209 int64 frame_id, |
210 bool is_main_frame, | 210 bool is_main_frame, |
211 int error_code) { | 211 int error_code) { |
212 ListValue args; | 212 ListValue args; |
213 DictionaryValue* dict = new DictionaryValue(); | 213 DictionaryValue* dict = new DictionaryValue(); |
214 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); | 214 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); |
215 dict->SetString(keys::kUrlKey, url.spec()); | 215 dict->SetString(keys::kUrlKey, url.spec()); |
216 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); | 216 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); |
217 dict->SetString(keys::kErrorKey, net::ErrorToString(error_code)); | 217 dict->SetString(keys::kErrorKey, net::ErrorToString(error_code)); |
218 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); | 218 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
219 args.Append(dict); | 219 args.Append(dict); |
220 | 220 |
221 std::string json_args; | 221 std::string json_args; |
222 base::JSONWriter::Write(&args, false, &json_args); | 222 base::JSONWriter::Write(&args, &json_args); |
223 DispatchEvent(web_contents->GetBrowserContext(), | 223 DispatchEvent(web_contents->GetBrowserContext(), |
224 keys::kOnErrorOccurred, | 224 keys::kOnErrorOccurred, |
225 json_args); | 225 json_args); |
226 } | 226 } |
227 | 227 |
228 } // namespace | 228 } // namespace |
229 | 229 |
230 | 230 |
231 // FrameNavigationState ------------------------------------------------------- | 231 // FrameNavigationState ------------------------------------------------------- |
232 | 232 |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 keys::kFrameIdKey, | 798 keys::kFrameIdKey, |
799 GetFrameId(navigation_state.IsMainFrame(*frame), *frame)); | 799 GetFrameId(navigation_state.IsMainFrame(*frame), *frame)); |
800 frameDict->SetBoolean( | 800 frameDict->SetBoolean( |
801 keys::kErrorOccurredKey, | 801 keys::kErrorOccurredKey, |
802 navigation_state.GetErrorOccurredInFrame(*frame)); | 802 navigation_state.GetErrorOccurredInFrame(*frame)); |
803 resultList->Append(frameDict); | 803 resultList->Append(frameDict); |
804 } | 804 } |
805 result_.reset(resultList); | 805 result_.reset(resultList); |
806 return true; | 806 return true; |
807 } | 807 } |
OLD | NEW |