| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/time.h" | 10 #include "base/time.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 registrar_.Add(this, | 113 registrar_.Add(this, |
| 114 NotificationType::FRAME_PROVISIONAL_LOAD_START, | 114 NotificationType::FRAME_PROVISIONAL_LOAD_START, |
| 115 NotificationService::AllSources()); | 115 NotificationService::AllSources()); |
| 116 registrar_.Add(this, | 116 registrar_.Add(this, |
| 117 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED, | 117 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED, |
| 118 NotificationService::AllSources()); | 118 NotificationService::AllSources()); |
| 119 registrar_.Add(this, | 119 registrar_.Add(this, |
| 120 NotificationType::FRAME_DOM_CONTENT_LOADED, | 120 NotificationType::FRAME_DOM_CONTENT_LOADED, |
| 121 NotificationService::AllSources()); | 121 NotificationService::AllSources()); |
| 122 registrar_.Add(this, | 122 registrar_.Add(this, |
| 123 NotificationType::FRAME_DID_FINISH_LOAD, |
| 124 NotificationService::AllSources()); |
| 125 registrar_.Add(this, |
| 123 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR, | 126 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR, |
| 124 NotificationService::AllSources()); | 127 NotificationService::AllSources()); |
| 125 registrar_.Add(this, | 128 registrar_.Add(this, |
| 126 NotificationType::TAB_CONTENTS_DESTROYED, | 129 NotificationType::TAB_CONTENTS_DESTROYED, |
| 127 NotificationService::AllSources()); | 130 NotificationService::AllSources()); |
| 128 } | 131 } |
| 129 } | 132 } |
| 130 | 133 |
| 131 void ExtensionWebNavigationEventRouter::Observe( | 134 void ExtensionWebNavigationEventRouter::Observe( |
| 132 NotificationType type, | 135 NotificationType type, |
| 133 const NotificationSource& source, | 136 const NotificationSource& source, |
| 134 const NotificationDetails& details) { | 137 const NotificationDetails& details) { |
| 135 switch (type.value) { | 138 switch (type.value) { |
| 136 case NotificationType::FRAME_PROVISIONAL_LOAD_START: | 139 case NotificationType::FRAME_PROVISIONAL_LOAD_START: |
| 137 FrameProvisionalLoadStart( | 140 FrameProvisionalLoadStart( |
| 138 Source<NavigationController>(source).ptr(), | 141 Source<NavigationController>(source).ptr(), |
| 139 Details<ProvisionalLoadDetails>(details).ptr()); | 142 Details<ProvisionalLoadDetails>(details).ptr()); |
| 140 break; | 143 break; |
| 141 case NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED: | 144 case NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED: |
| 142 FrameProvisionalLoadCommitted( | 145 FrameProvisionalLoadCommitted( |
| 143 Source<NavigationController>(source).ptr(), | 146 Source<NavigationController>(source).ptr(), |
| 144 Details<ProvisionalLoadDetails>(details).ptr()); | 147 Details<ProvisionalLoadDetails>(details).ptr()); |
| 145 break; | 148 break; |
| 146 case NotificationType::FRAME_DOM_CONTENT_LOADED: | 149 case NotificationType::FRAME_DOM_CONTENT_LOADED: |
| 147 FrameDomContentLoaded( | 150 FrameDomContentLoaded( |
| 148 Source<NavigationController>(source).ptr(), | 151 Source<NavigationController>(source).ptr(), |
| 149 *Details<long long>(details).ptr()); | 152 *Details<long long>(details).ptr()); |
| 150 break; | 153 break; |
| 154 case NotificationType::FRAME_DID_FINISH_LOAD: |
| 155 FrameDidFinishLoad( |
| 156 Source<NavigationController>(source).ptr(), |
| 157 *Details<long long>(details).ptr()); |
| 158 break; |
| 151 case NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR: | 159 case NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR: |
| 152 FailProvisionalLoadWithError( | 160 FailProvisionalLoadWithError( |
| 153 Source<NavigationController>(source).ptr(), | 161 Source<NavigationController>(source).ptr(), |
| 154 Details<ProvisionalLoadDetails>(details).ptr()); | 162 Details<ProvisionalLoadDetails>(details).ptr()); |
| 155 break; | 163 break; |
| 156 | 164 |
| 157 case NotificationType::TAB_CONTENTS_DESTROYED: | 165 case NotificationType::TAB_CONTENTS_DESTROYED: |
| 158 navigation_state_.RemoveTabContentsState( | 166 navigation_state_.RemoveTabContentsState( |
| 159 Source<TabContents>(source).ptr()); | 167 Source<TabContents>(source).ptr()); |
| 160 break; | 168 break; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 dict->SetInteger(keys::kFrameIdKey, navigation_state_.IsMainFrame(frame_id) ? | 234 dict->SetInteger(keys::kFrameIdKey, navigation_state_.IsMainFrame(frame_id) ? |
| 227 0 : static_cast<int>(frame_id)); | 235 0 : static_cast<int>(frame_id)); |
| 228 dict->SetReal(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); | 236 dict->SetReal(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
| 229 args.Append(dict); | 237 args.Append(dict); |
| 230 | 238 |
| 231 std::string json_args; | 239 std::string json_args; |
| 232 base::JSONWriter::Write(&args, false, &json_args); | 240 base::JSONWriter::Write(&args, false, &json_args); |
| 233 DispatchEvent(controller->profile(), keys::kOnDOMContentLoaded, json_args); | 241 DispatchEvent(controller->profile(), keys::kOnDOMContentLoaded, json_args); |
| 234 } | 242 } |
| 235 | 243 |
| 244 void ExtensionWebNavigationEventRouter::FrameDidFinishLoad( |
| 245 NavigationController* controller, long long frame_id) { |
| 246 if (!navigation_state_.CanSendEvents(frame_id)) |
| 247 return; |
| 248 ListValue args; |
| 249 DictionaryValue* dict = new DictionaryValue(); |
| 250 dict->SetInteger(keys::kTabIdKey, |
| 251 ExtensionTabUtil::GetTabId(controller->tab_contents())); |
| 252 dict->SetString(keys::kUrlKey, navigation_state_.GetUrl(frame_id).spec()); |
| 253 dict->SetInteger(keys::kFrameIdKey, navigation_state_.IsMainFrame(frame_id) ? |
| 254 0 : static_cast<int>(frame_id)); |
| 255 dict->SetReal(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); |
| 256 args.Append(dict); |
| 257 |
| 258 std::string json_args; |
| 259 base::JSONWriter::Write(&args, false, &json_args); |
| 260 DispatchEvent(controller->profile(), keys::kOnCompleted, json_args); |
| 261 } |
| 262 |
| 236 void ExtensionWebNavigationEventRouter::FailProvisionalLoadWithError( | 263 void ExtensionWebNavigationEventRouter::FailProvisionalLoadWithError( |
| 237 NavigationController* controller, | 264 NavigationController* controller, |
| 238 ProvisionalLoadDetails* details) { | 265 ProvisionalLoadDetails* details) { |
| 239 if (!navigation_state_.CanSendEvents(details->frame_id())) | 266 if (!navigation_state_.CanSendEvents(details->frame_id())) |
| 240 return; | 267 return; |
| 241 ListValue args; | 268 ListValue args; |
| 242 DictionaryValue* dict = new DictionaryValue(); | 269 DictionaryValue* dict = new DictionaryValue(); |
| 243 dict->SetInteger(keys::kTabIdKey, | 270 dict->SetInteger(keys::kTabIdKey, |
| 244 ExtensionTabUtil::GetTabId(controller->tab_contents())); | 271 ExtensionTabUtil::GetTabId(controller->tab_contents())); |
| 245 dict->SetString(keys::kUrlKey, | 272 dict->SetString(keys::kUrlKey, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 258 | 285 |
| 259 void ExtensionWebNavigationEventRouter::DispatchEvent( | 286 void ExtensionWebNavigationEventRouter::DispatchEvent( |
| 260 Profile* profile, | 287 Profile* profile, |
| 261 const char* event_name, | 288 const char* event_name, |
| 262 const std::string& json_args) { | 289 const std::string& json_args) { |
| 263 if (profile && profile->GetExtensionEventRouter()) { | 290 if (profile && profile->GetExtensionEventRouter()) { |
| 264 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 291 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 265 event_name, json_args, profile, GURL()); | 292 event_name, json_args, profile, GURL()); |
| 266 } | 293 } |
| 267 } | 294 } |
| OLD | NEW |