| 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 #include "chrome/browser/devtools/devtools_window.h" |     5 #include "chrome/browser/devtools/devtools_window.h" | 
|     6 #include <algorithm> |     6 #include <algorithm> | 
|     7  |     7  | 
|     8 #include "base/command_line.h" |     8 #include "base/command_line.h" | 
|     9 #include "base/json/json_reader.h" |     9 #include "base/json/json_reader.h" | 
|    10 #include "base/json/json_writer.h" |    10 #include "base/json/json_writer.h" | 
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   475 // static |   475 // static | 
|   476 int DevToolsWindow::GetMinimizedHeight() { |   476 int DevToolsWindow::GetMinimizedHeight() { | 
|   477   const int kMinimizedDevToolsHeight = 24; |   477   const int kMinimizedDevToolsHeight = 24; | 
|   478   return kMinimizedDevToolsHeight; |   478   return kMinimizedDevToolsHeight; | 
|   479 } |   479 } | 
|   480  |   480  | 
|   481 void DevToolsWindow::InspectedContentsClosing() { |   481 void DevToolsWindow::InspectedContentsClosing() { | 
|   482   intercepted_page_beforeunload_ = false; |   482   intercepted_page_beforeunload_ = false; | 
|   483   // This will prevent any activity after frontend is loaded. |   483   // This will prevent any activity after frontend is loaded. | 
|   484   action_on_load_ = DevToolsToggleAction::NoOp(); |   484   action_on_load_ = DevToolsToggleAction::NoOp(); | 
 |   485   ignore_set_is_docked_ = true; | 
|   485   web_contents_->GetRenderViewHost()->ClosePage(); |   486   web_contents_->GetRenderViewHost()->ClosePage(); | 
|   486 } |   487 } | 
|   487  |   488  | 
|   488 content::RenderViewHost* DevToolsWindow::GetRenderViewHost() { |   489 content::RenderViewHost* DevToolsWindow::GetRenderViewHost() { | 
|   489   return web_contents_->GetRenderViewHost(); |   490   return web_contents_->GetRenderViewHost(); | 
|   490 } |   491 } | 
|   491  |   492  | 
|   492 gfx::Insets DevToolsWindow::GetContentsInsets() const { |   493 gfx::Insets DevToolsWindow::GetContentsInsets() const { | 
|   493   return contents_insets_; |   494   return contents_insets_; | 
|   494 } |   495 } | 
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   645                                bool can_dock) |   646                                bool can_dock) | 
|   646     : profile_(profile), |   647     : profile_(profile), | 
|   647       browser_(NULL), |   648       browser_(NULL), | 
|   648       is_docked_(true), |   649       is_docked_(true), | 
|   649       can_dock_(can_dock), |   650       can_dock_(can_dock), | 
|   650       // This initialization allows external front-end to work without changes. |   651       // This initialization allows external front-end to work without changes. | 
|   651       // We don't wait for docking call, but instead immediately show undocked. |   652       // We don't wait for docking call, but instead immediately show undocked. | 
|   652       // Passing "dockSide=undocked" parameter ensures proper UI. |   653       // Passing "dockSide=undocked" parameter ensures proper UI. | 
|   653       load_state_(can_dock ? kNotLoaded : kIsDockedSet), |   654       load_state_(can_dock ? kNotLoaded : kIsDockedSet), | 
|   654       action_on_load_(DevToolsToggleAction::NoOp()), |   655       action_on_load_(DevToolsToggleAction::NoOp()), | 
|   655       ignore_set_is_docked_for_test_(false), |   656       ignore_set_is_docked_(false), | 
|   656       intercepted_page_beforeunload_(false), |   657       intercepted_page_beforeunload_(false), | 
|   657       weak_factory_(this) { |   658       weak_factory_(this) { | 
|   658   web_contents_ = |   659   web_contents_ = | 
|   659       content::WebContents::Create(content::WebContents::CreateParams(profile)); |   660       content::WebContents::Create(content::WebContents::CreateParams(profile)); | 
|   660   frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); |   661   frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); | 
|   661  |   662  | 
|   662   // Set up delegate, so we get fully-functional window immediately. |   663   // Set up delegate, so we get fully-functional window immediately. | 
|   663   // It will not appear in UI though until |load_state_ == kLoadCompleted|. |   664   // It will not appear in UI though until |load_state_ == kLoadCompleted|. | 
|   664   web_contents_->SetDelegate(this); |   665   web_contents_->SetDelegate(this); | 
|   665  |   666  | 
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   832     inspected_web_contents->GetDelegate()->AddNewContents( |   833     inspected_web_contents->GetDelegate()->AddNewContents( | 
|   833         source, new_contents, disposition, initial_pos, user_gesture, |   834         source, new_contents, disposition, initial_pos, user_gesture, | 
|   834         was_blocked); |   835         was_blocked); | 
|   835   } |   836   } | 
|   836 } |   837 } | 
|   837  |   838  | 
|   838 void DevToolsWindow::CloseContents(content::WebContents* source) { |   839 void DevToolsWindow::CloseContents(content::WebContents* source) { | 
|   839   CHECK(is_docked_); |   840   CHECK(is_docked_); | 
|   840   // This will prevent any activity after frontend is loaded. |   841   // This will prevent any activity after frontend is loaded. | 
|   841   action_on_load_ = DevToolsToggleAction::NoOp(); |   842   action_on_load_ = DevToolsToggleAction::NoOp(); | 
 |   843   ignore_set_is_docked_ = true; | 
|   842   // Update dev tools to reflect removed dev tools window. |   844   // Update dev tools to reflect removed dev tools window. | 
|   843   BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |   845   BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 
|   844   if (inspected_window) |   846   if (inspected_window) | 
|   845     inspected_window->UpdateDevTools(); |   847     inspected_window->UpdateDevTools(); | 
|   846   // In case of docked web_contents_, we own it so delete here. |   848   // In case of docked web_contents_, we own it so delete here. | 
|   847   // Embedding DevTools window will be deleted as a result of |   849   // Embedding DevTools window will be deleted as a result of | 
|   848   // WebContentsDestroyed callback. |   850   // WebContentsDestroyed callback. | 
|   849   delete web_contents_; |   851   delete web_contents_; | 
|   850 } |   852 } | 
|   851  |   853  | 
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   971     inspected_tab->GetDelegate()->ActivateContents(inspected_tab); |   973     inspected_tab->GetDelegate()->ActivateContents(inspected_tab); | 
|   972   } else { |   974   } else { | 
|   973     browser_->window()->Activate(); |   975     browser_->window()->Activate(); | 
|   974   } |   976   } | 
|   975 } |   977 } | 
|   976  |   978  | 
|   977 void DevToolsWindow::CloseWindow() { |   979 void DevToolsWindow::CloseWindow() { | 
|   978   DCHECK(is_docked_); |   980   DCHECK(is_docked_); | 
|   979   // This will prevent any activity after frontend is loaded. |   981   // This will prevent any activity after frontend is loaded. | 
|   980   action_on_load_ = DevToolsToggleAction::NoOp(); |   982   action_on_load_ = DevToolsToggleAction::NoOp(); | 
 |   983   ignore_set_is_docked_ = true; | 
|   981   web_contents_->GetRenderViewHost()->FirePageBeforeUnload(false); |   984   web_contents_->GetRenderViewHost()->FirePageBeforeUnload(false); | 
|   982 } |   985 } | 
|   983  |   986  | 
|   984 void DevToolsWindow::SetContentsInsets( |   987 void DevToolsWindow::SetContentsInsets( | 
|   985     int top, int left, int bottom, int right) { |   988     int top, int left, int bottom, int right) { | 
|   986   if (contents_insets_.top() == top && |   989   if (contents_insets_.top() == top && | 
|   987       contents_insets_.left() == left && |   990       contents_insets_.left() == left && | 
|   988       contents_insets_.bottom() == bottom && |   991       contents_insets_.bottom() == bottom && | 
|   989       contents_insets_.right() == right) { |   992       contents_insets_.right() == right) { | 
|   990     return; |   993     return; | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|  1015     is_docked_ = is_docked; |  1018     is_docked_ = is_docked; | 
|  1016     // Load is completed when both kIsDockedSet and kOnLoadFired happened. |  1019     // Load is completed when both kIsDockedSet and kOnLoadFired happened. | 
|  1017     // Note that kIsDockedSet may be already set when can_dock_ is false. |  1020     // Note that kIsDockedSet may be already set when can_dock_ is false. | 
|  1018     load_state_ = load_state_ == kOnLoadFired ? kLoadCompleted : kIsDockedSet; |  1021     load_state_ = load_state_ == kOnLoadFired ? kLoadCompleted : kIsDockedSet; | 
|  1019     // Note that action_on_load_ will be performed after the load is actually |  1022     // Note that action_on_load_ will be performed after the load is actually | 
|  1020     // completed. For now, just show the window. |  1023     // completed. For now, just show the window. | 
|  1021     Show(DevToolsToggleAction::Show()); |  1024     Show(DevToolsToggleAction::Show()); | 
|  1022     if (load_state_ == kLoadCompleted) |  1025     if (load_state_ == kLoadCompleted) | 
|  1023       LoadCompleted(); |  1026       LoadCompleted(); | 
|  1024   } |  1027   } | 
|  1025   ignore_set_is_docked_for_test_ = true; |  1028   ignore_set_is_docked_ = true; | 
|  1026 } |  1029 } | 
|  1027  |  1030  | 
|  1028 void DevToolsWindow::SetIsDocked(bool dock_requested) { |  1031 void DevToolsWindow::SetIsDocked(bool dock_requested) { | 
|  1029   if (ignore_set_is_docked_for_test_) |  1032   if (ignore_set_is_docked_) | 
|  1030     return; |  1033     return; | 
|  1031  |  1034  | 
|  1032   DCHECK(can_dock_ || !dock_requested); |  1035   DCHECK(can_dock_ || !dock_requested); | 
|  1033   if (!can_dock_) |  1036   if (!can_dock_) | 
|  1034     dock_requested = false; |  1037     dock_requested = false; | 
|  1035  |  1038  | 
|  1036   bool was_docked = is_docked_; |  1039   bool was_docked = is_docked_; | 
|  1037   is_docked_ = dock_requested; |  1040   is_docked_ = dock_requested; | 
|  1038  |  1041  | 
|  1039   if (load_state_ != kLoadCompleted) { |  1042   if (load_state_ != kLoadCompleted) { | 
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1473   if (load_state_ == kLoadCompleted) |  1476   if (load_state_ == kLoadCompleted) | 
|  1474     LoadCompleted(); |  1477     LoadCompleted(); | 
|  1475 } |  1478 } | 
|  1476  |  1479  | 
|  1477 void DevToolsWindow::LoadCompleted() { |  1480 void DevToolsWindow::LoadCompleted() { | 
|  1478   Show(action_on_load_); |  1481   Show(action_on_load_); | 
|  1479   action_on_load_ = DevToolsToggleAction::NoOp(); |  1482   action_on_load_ = DevToolsToggleAction::NoOp(); | 
|  1480   UpdateTheme(); |  1483   UpdateTheme(); | 
|  1481   AddDevToolsExtensionsToClient(); |  1484   AddDevToolsExtensionsToClient(); | 
|  1482 } |  1485 } | 
| OLD | NEW |