OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "chrome/browser/devtools/devtools_ui_bindings.h" | 5 #include "chrome/browser/devtools/devtools_ui_bindings.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
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" |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 DevToolsUIBindings::FrontendWebContentsObserver:: | 252 DevToolsUIBindings::FrontendWebContentsObserver:: |
253 ~FrontendWebContentsObserver() { | 253 ~FrontendWebContentsObserver() { |
254 } | 254 } |
255 | 255 |
256 void DevToolsUIBindings::FrontendWebContentsObserver::WebContentsDestroyed() { | 256 void DevToolsUIBindings::FrontendWebContentsObserver::WebContentsDestroyed() { |
257 delete devtools_bindings_; | 257 delete devtools_bindings_; |
258 } | 258 } |
259 | 259 |
260 void DevToolsUIBindings::FrontendWebContentsObserver::RenderProcessGone( | 260 void DevToolsUIBindings::FrontendWebContentsObserver::RenderProcessGone( |
261 base::TerminationStatus status) { | 261 base::TerminationStatus status) { |
262 switch (status) { | |
263 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: | |
264 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | |
265 case base::TERMINATION_STATUS_PROCESS_CRASHED: | |
266 content::DevToolsManager::GetInstance()->ClientHostClosing( | |
267 devtools_bindings_); | |
268 break; | |
269 default: | |
270 break; | |
271 } | |
262 devtools_bindings_->delegate_->RenderProcessGone(); | 272 devtools_bindings_->delegate_->RenderProcessGone(); |
263 } | 273 } |
264 | 274 |
265 void DevToolsUIBindings::FrontendWebContentsObserver::AboutToNavigateRenderView( | 275 void DevToolsUIBindings::FrontendWebContentsObserver::AboutToNavigateRenderView( |
266 content::RenderViewHost* render_view_host) { | 276 content::RenderViewHost* render_view_host) { |
267 content::NavigationEntry* entry = | 277 content::NavigationEntry* entry = |
268 web_contents()->GetController().GetActiveEntry(); | 278 web_contents()->GetController().GetActiveEntry(); |
269 if (devtools_bindings_->url_ == entry->GetURL()) | 279 if (devtools_bindings_->url_ != entry->GetURL()) |
270 content::DevToolsClientHost::SetupDevToolsFrontendClient(render_view_host); | |
271 else | |
272 delete devtools_bindings_; | 280 delete devtools_bindings_; |
273 } | 281 } |
274 | 282 |
275 void DevToolsUIBindings::FrontendWebContentsObserver:: | 283 void DevToolsUIBindings::FrontendWebContentsObserver:: |
276 DocumentOnLoadCompletedInMainFrame() { | 284 DocumentOnLoadCompletedInMainFrame() { |
277 devtools_bindings_->DocumentOnLoadCompletedInMainFrame(); | 285 devtools_bindings_->DocumentOnLoadCompletedInMainFrame(); |
278 } | 286 } |
279 | 287 |
280 // DevToolsUIBindings --------------------------------------------------------- | 288 // DevToolsUIBindings --------------------------------------------------------- |
281 | 289 |
(...skipping 22 matching lines...) Expand all Loading... | |
304 : profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 312 : profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
305 web_contents_(web_contents), | 313 web_contents_(web_contents), |
306 delegate_(new DefaultBindingsDelegate(web_contents_)), | 314 delegate_(new DefaultBindingsDelegate(web_contents_)), |
307 device_count_updates_enabled_(false), | 315 device_count_updates_enabled_(false), |
308 devices_updates_enabled_(false), | 316 devices_updates_enabled_(false), |
309 url_(url), | 317 url_(url), |
310 weak_factory_(this) { | 318 weak_factory_(this) { |
311 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); | 319 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); |
312 web_contents_->GetMutableRendererPrefs()->can_accept_load_drops = false; | 320 web_contents_->GetMutableRendererPrefs()->can_accept_load_drops = false; |
313 | 321 |
314 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost( | 322 frontend_host_.reset(content::DevToolsFrontendHost::Create( |
315 web_contents_, this)); | 323 web_contents_, this)); |
316 file_helper_.reset(new DevToolsFileHelper(web_contents_, profile_)); | 324 file_helper_.reset(new DevToolsFileHelper(web_contents_, profile_)); |
317 file_system_indexer_ = new DevToolsFileSystemIndexer(); | 325 file_system_indexer_ = new DevToolsFileSystemIndexer(); |
318 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 326 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
319 web_contents_); | 327 web_contents_); |
320 | 328 |
321 web_contents_->GetController().LoadURL( | 329 web_contents_->GetController().LoadURL( |
322 url, content::Referrer(), | 330 url, content::Referrer(), |
323 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); | 331 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); |
324 | 332 |
325 // Wipe out page icon so that the default application icon is used. | 333 // Wipe out page icon so that the default application icon is used. |
326 content::NavigationEntry* entry = | 334 content::NavigationEntry* entry = |
327 web_contents_->GetController().GetActiveEntry(); | 335 web_contents_->GetController().GetActiveEntry(); |
328 entry->GetFavicon().image = gfx::Image(); | 336 entry->GetFavicon().image = gfx::Image(); |
329 entry->GetFavicon().valid = true; | 337 entry->GetFavicon().valid = true; |
330 | 338 |
331 // Register on-load actions. | 339 // Register on-load actions. |
332 registrar_.Add( | 340 registrar_.Add( |
333 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 341 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
334 content::Source<ThemeService>( | 342 content::Source<ThemeService>( |
335 ThemeServiceFactory::GetForProfile(profile_))); | 343 ThemeServiceFactory::GetForProfile(profile_))); |
336 | 344 |
337 embedder_message_dispatcher_.reset( | 345 embedder_message_dispatcher_.reset( |
338 DevToolsEmbedderMessageDispatcher::createForDevToolsFrontend(this)); | 346 DevToolsEmbedderMessageDispatcher::createForDevToolsFrontend(this)); |
339 } | 347 } |
340 | 348 |
341 DevToolsUIBindings::~DevToolsUIBindings() { | 349 DevToolsUIBindings::~DevToolsUIBindings() { |
342 content::DevToolsManager::GetInstance()->ClientHostClosing( | 350 content::DevToolsManager::GetInstance()->ClientHostClosing(this); |
343 frontend_host_.get()); | |
344 | 351 |
345 for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin()); | 352 for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin()); |
346 jobs_it != indexing_jobs_.end(); ++jobs_it) { | 353 jobs_it != indexing_jobs_.end(); ++jobs_it) { |
347 jobs_it->second->Stop(); | 354 jobs_it->second->Stop(); |
348 } | 355 } |
349 indexing_jobs_.clear(); | 356 indexing_jobs_.clear(); |
350 SetDeviceCountUpdatesEnabled(false); | 357 SetDeviceCountUpdatesEnabled(false); |
351 SetDevicesUpdatesEnabled(false); | 358 SetDevicesUpdatesEnabled(false); |
352 } | 359 } |
353 | 360 |
354 void DevToolsUIBindings::InspectedContentsClosing() { | 361 // content::NotificationObserver overrides ------------------------------------ |
355 delegate_->InspectedContentsClosing(); | |
356 } | |
357 | |
358 void DevToolsUIBindings::Observe(int type, | 362 void DevToolsUIBindings::Observe(int type, |
359 const content::NotificationSource& source, | 363 const content::NotificationSource& source, |
360 const content::NotificationDetails& details) { | 364 const content::NotificationDetails& details) { |
361 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); | 365 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); |
362 UpdateTheme(); | 366 UpdateTheme(); |
363 } | 367 } |
364 | 368 |
365 void DevToolsUIBindings::DispatchOnEmbedder(const std::string& message) { | 369 // content::DevToolsFrontendHost::Delegate implementation --------------------- |
370 bool DevToolsUIBindings::ShouldSetupDevToolsFrontendForUrl(const GURL& url) { | |
371 return url.SchemeIs(content::kChromeDevToolsScheme); | |
pfeldman
2014/07/31 11:47:25
It seems like we can make this decision in content
| |
372 } | |
373 | |
374 void DevToolsUIBindings::HandleMessageFromDevToolsFrontend( | |
375 const std::string& message) { | |
366 std::string method; | 376 std::string method; |
367 base::ListValue empty_params; | 377 base::ListValue empty_params; |
368 base::ListValue* params = &empty_params; | 378 base::ListValue* params = &empty_params; |
369 | 379 |
370 base::DictionaryValue* dict = NULL; | 380 base::DictionaryValue* dict = NULL; |
371 scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message)); | 381 scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message)); |
372 if (!parsed_message || | 382 if (!parsed_message || |
373 !parsed_message->GetAsDictionary(&dict) || | 383 !parsed_message->GetAsDictionary(&dict) || |
374 !dict->GetString(kFrontendHostMethod, &method) || | 384 !dict->GetString(kFrontendHostMethod, &method) || |
375 (dict->HasKey(kFrontendHostParams) && | 385 (dict->HasKey(kFrontendHostParams) && |
376 !dict->GetList(kFrontendHostParams, ¶ms))) { | 386 !dict->GetList(kFrontendHostParams, ¶ms))) { |
377 LOG(ERROR) << "Invalid message was sent to embedder: " << message; | 387 LOG(ERROR) << "Invalid message was sent to embedder: " << message; |
378 return; | 388 return; |
379 } | 389 } |
380 | 390 |
381 int id = 0; | 391 int id = 0; |
382 dict->GetInteger(kFrontendHostId, &id); | 392 dict->GetInteger(kFrontendHostId, &id); |
383 | 393 |
384 std::string error; | 394 std::string error; |
385 embedder_message_dispatcher_->Dispatch(method, params, &error); | 395 embedder_message_dispatcher_->Dispatch(method, params, &error); |
386 if (id) { | 396 if (id) { |
387 base::FundamentalValue id_value(id); | 397 base::FundamentalValue id_value(id); |
388 base::StringValue error_value(error); | 398 base::StringValue error_value(error); |
389 CallClientFunction("InspectorFrontendAPI.embedderMessageAck", | 399 CallClientFunction("InspectorFrontendAPI.embedderMessageAck", |
390 &id_value, &error_value, NULL); | 400 &id_value, &error_value, NULL); |
391 } | 401 } |
392 } | 402 } |
393 | 403 |
404 void DevToolsUIBindings::HandleMessageFromDevToolsFrontendToBackend( | |
405 const std::string& message) { | |
406 content::DevToolsManager::GetInstance()->DispatchOnInspectorBackend( | |
407 this, message); | |
408 } | |
409 | |
410 // content::DevToolsClientHost implementation --------------------------------- | |
411 void DevToolsUIBindings::DispatchOnInspectorFrontend( | |
412 const std::string& message) { | |
413 frontend_host_->DispatchOnDevToolsFrontend(message); | |
pfeldman
2014/07/31 11:47:25
Can we use a CallClientFunction here?
dgozman
2014/07/31 13:05:31
There is a TODO for that. It requires some blink-s
| |
414 } | |
415 | |
416 void DevToolsUIBindings::InspectedContentsClosing() { | |
417 delegate_->InspectedContentsClosing(); | |
418 } | |
419 | |
420 void DevToolsUIBindings::ReplacedWithAnotherClient() { | |
421 } | |
422 | |
423 // DevToolsEmbedderMessageDispatcher::Delegate implementation ----------------- | |
394 void DevToolsUIBindings::ActivateWindow() { | 424 void DevToolsUIBindings::ActivateWindow() { |
395 delegate_->ActivateWindow(); | 425 delegate_->ActivateWindow(); |
396 } | 426 } |
397 | 427 |
398 void DevToolsUIBindings::CloseWindow() { | 428 void DevToolsUIBindings::CloseWindow() { |
399 delegate_->CloseWindow(); | 429 delegate_->CloseWindow(); |
400 } | 430 } |
401 | 431 |
402 void DevToolsUIBindings::SetInspectedPageBounds(const gfx::Rect& rect) { | 432 void DevToolsUIBindings::SetInspectedPageBounds(const gfx::Rect& rect) { |
403 delegate_->SetInspectedPageBounds(rect); | 433 delegate_->SetInspectedPageBounds(rect); |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
771 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); | 801 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); |
772 } | 802 } |
773 | 803 |
774 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { | 804 void DevToolsUIBindings::DocumentOnLoadCompletedInMainFrame() { |
775 // Call delegate first - it seeds importants bit of information. | 805 // Call delegate first - it seeds importants bit of information. |
776 delegate_->OnLoadCompleted(); | 806 delegate_->OnLoadCompleted(); |
777 | 807 |
778 UpdateTheme(); | 808 UpdateTheme(); |
779 AddDevToolsExtensionsToClient(); | 809 AddDevToolsExtensionsToClient(); |
780 } | 810 } |
OLD | NEW |