Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: chrome/browser/devtools/devtools_ui_bindings.cc

Issue 427143003: [DevTools] Move DevToolsClientHost functionality out of DevToolsFrontendHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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); 280 devtools_bindings_->frontend_host_.reset(
271 else 281 content::DevToolsFrontendHost::Create(
282 render_view_host, devtools_bindings_));
283 } else {
272 delete devtools_bindings_; 284 delete devtools_bindings_;
285 }
273 } 286 }
274 287
275 void DevToolsUIBindings::FrontendWebContentsObserver:: 288 void DevToolsUIBindings::FrontendWebContentsObserver::
276 DocumentOnLoadCompletedInMainFrame() { 289 DocumentOnLoadCompletedInMainFrame() {
277 devtools_bindings_->DocumentOnLoadCompletedInMainFrame(); 290 devtools_bindings_->DocumentOnLoadCompletedInMainFrame();
278 } 291 }
279 292
280 // DevToolsUIBindings --------------------------------------------------------- 293 // DevToolsUIBindings ---------------------------------------------------------
281 294
282 // static 295 // static
(...skipping 21 matching lines...) Expand all
304 : profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), 317 : profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())),
305 web_contents_(web_contents), 318 web_contents_(web_contents),
306 delegate_(new DefaultBindingsDelegate(web_contents_)), 319 delegate_(new DefaultBindingsDelegate(web_contents_)),
307 device_count_updates_enabled_(false), 320 device_count_updates_enabled_(false),
308 devices_updates_enabled_(false), 321 devices_updates_enabled_(false),
309 url_(url), 322 url_(url),
310 weak_factory_(this) { 323 weak_factory_(this) {
311 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); 324 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this));
312 web_contents_->GetMutableRendererPrefs()->can_accept_load_drops = false; 325 web_contents_->GetMutableRendererPrefs()->can_accept_load_drops = false;
313 326
314 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost(
315 web_contents_, this));
316 file_helper_.reset(new DevToolsFileHelper(web_contents_, profile_)); 327 file_helper_.reset(new DevToolsFileHelper(web_contents_, profile_));
317 file_system_indexer_ = new DevToolsFileSystemIndexer(); 328 file_system_indexer_ = new DevToolsFileSystemIndexer();
318 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( 329 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
319 web_contents_); 330 web_contents_);
320 331
321 web_contents_->GetController().LoadURL( 332 web_contents_->GetController().LoadURL(
322 url, content::Referrer(), 333 url, content::Referrer(),
323 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); 334 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
324 335
325 // Wipe out page icon so that the default application icon is used. 336 // Wipe out page icon so that the default application icon is used.
326 content::NavigationEntry* entry = 337 content::NavigationEntry* entry =
327 web_contents_->GetController().GetActiveEntry(); 338 web_contents_->GetController().GetActiveEntry();
328 entry->GetFavicon().image = gfx::Image(); 339 entry->GetFavicon().image = gfx::Image();
329 entry->GetFavicon().valid = true; 340 entry->GetFavicon().valid = true;
330 341
331 // Register on-load actions. 342 // Register on-load actions.
332 registrar_.Add( 343 registrar_.Add(
333 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 344 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
334 content::Source<ThemeService>( 345 content::Source<ThemeService>(
335 ThemeServiceFactory::GetForProfile(profile_))); 346 ThemeServiceFactory::GetForProfile(profile_)));
336 347
337 embedder_message_dispatcher_.reset( 348 embedder_message_dispatcher_.reset(
338 DevToolsEmbedderMessageDispatcher::createForDevToolsFrontend(this)); 349 DevToolsEmbedderMessageDispatcher::createForDevToolsFrontend(this));
339 } 350 }
340 351
341 DevToolsUIBindings::~DevToolsUIBindings() { 352 DevToolsUIBindings::~DevToolsUIBindings() {
342 content::DevToolsManager::GetInstance()->ClientHostClosing( 353 content::DevToolsManager::GetInstance()->ClientHostClosing(this);
343 frontend_host_.get());
344 354
345 for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin()); 355 for (IndexingJobsMap::const_iterator jobs_it(indexing_jobs_.begin());
346 jobs_it != indexing_jobs_.end(); ++jobs_it) { 356 jobs_it != indexing_jobs_.end(); ++jobs_it) {
347 jobs_it->second->Stop(); 357 jobs_it->second->Stop();
348 } 358 }
349 indexing_jobs_.clear(); 359 indexing_jobs_.clear();
350 SetDeviceCountUpdatesEnabled(false); 360 SetDeviceCountUpdatesEnabled(false);
351 SetDevicesUpdatesEnabled(false); 361 SetDevicesUpdatesEnabled(false);
352 } 362 }
353 363
354 void DevToolsUIBindings::InspectedContentsClosing() { 364 // content::NotificationObserver overrides ------------------------------------
355 delegate_->InspectedContentsClosing();
356 }
357
358 void DevToolsUIBindings::Observe(int type, 365 void DevToolsUIBindings::Observe(int type,
359 const content::NotificationSource& source, 366 const content::NotificationSource& source,
360 const content::NotificationDetails& details) { 367 const content::NotificationDetails& details) {
361 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); 368 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type);
362 UpdateTheme(); 369 UpdateTheme();
363 } 370 }
364 371
365 void DevToolsUIBindings::DispatchOnEmbedder(const std::string& message) { 372 // content::DevToolsFrontendHost::Delegate implementation ---------------------
373 void DevToolsUIBindings::HandleMessageFromDevToolsFrontend(
374 const std::string& message) {
366 std::string method; 375 std::string method;
367 base::ListValue empty_params; 376 base::ListValue empty_params;
368 base::ListValue* params = &empty_params; 377 base::ListValue* params = &empty_params;
369 378
370 base::DictionaryValue* dict = NULL; 379 base::DictionaryValue* dict = NULL;
371 scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message)); 380 scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message));
372 if (!parsed_message || 381 if (!parsed_message ||
373 !parsed_message->GetAsDictionary(&dict) || 382 !parsed_message->GetAsDictionary(&dict) ||
374 !dict->GetString(kFrontendHostMethod, &method) || 383 !dict->GetString(kFrontendHostMethod, &method) ||
375 (dict->HasKey(kFrontendHostParams) && 384 (dict->HasKey(kFrontendHostParams) &&
376 !dict->GetList(kFrontendHostParams, &params))) { 385 !dict->GetList(kFrontendHostParams, &params))) {
377 LOG(ERROR) << "Invalid message was sent to embedder: " << message; 386 LOG(ERROR) << "Invalid message was sent to embedder: " << message;
378 return; 387 return;
379 } 388 }
380 389
381 int id = 0; 390 int id = 0;
382 dict->GetInteger(kFrontendHostId, &id); 391 dict->GetInteger(kFrontendHostId, &id);
383 392
384 std::string error; 393 std::string error;
385 embedder_message_dispatcher_->Dispatch(method, params, &error); 394 embedder_message_dispatcher_->Dispatch(method, params, &error);
386 if (id) { 395 if (id) {
387 base::FundamentalValue id_value(id); 396 base::FundamentalValue id_value(id);
388 base::StringValue error_value(error); 397 base::StringValue error_value(error);
389 CallClientFunction("InspectorFrontendAPI.embedderMessageAck", 398 CallClientFunction("InspectorFrontendAPI.embedderMessageAck",
390 &id_value, &error_value, NULL); 399 &id_value, &error_value, NULL);
391 } 400 }
392 } 401 }
393 402
403 void DevToolsUIBindings::HandleMessageFromDevToolsFrontendToBackend(
404 const std::string& message) {
405 content::DevToolsManager::GetInstance()->DispatchOnInspectorBackend(
406 this, message);
407 }
408
409 // content::DevToolsClientHost implementation ---------------------------------
410 void DevToolsUIBindings::DispatchOnInspectorFrontend(
411 const std::string& message) {
412 if (frontend_host_)
413 frontend_host_->DispatchOnDevToolsFrontend(message);
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698