| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/gtk/extensions/extension_popup_gtk.h" | 5 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 anchor_(anchor), | 43 anchor_(anchor), |
| 44 being_inspected_(inspect), | 44 being_inspected_(inspect), |
| 45 method_factory_(this) { | 45 method_factory_(this) { |
| 46 host_->view()->SetContainer(this); | 46 host_->view()->SetContainer(this); |
| 47 | 47 |
| 48 // If the host had somehow finished loading, then we'd miss the notification | 48 // If the host had somehow finished loading, then we'd miss the notification |
| 49 // and not show. This seems to happen in single-process mode. | 49 // and not show. This seems to happen in single-process mode. |
| 50 if (host->did_stop_loading()) { | 50 if (host->did_stop_loading()) { |
| 51 ShowPopup(); | 51 ShowPopup(); |
| 52 } else { | 52 } else { |
| 53 registrar_.Add(this, NotificationType::EXTENSION_HOST_DID_STOP_LOADING, | 53 registrar_.Add(this, chrome::EXTENSION_HOST_DID_STOP_LOADING, |
| 54 Source<Profile>(host->profile())); | 54 Source<Profile>(host->profile())); |
| 55 } | 55 } |
| 56 | 56 |
| 57 registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 57 registrar_.Add(this, chrome::EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 58 Source<Profile>(host->profile())); | 58 Source<Profile>(host->profile())); |
| 59 } | 59 } |
| 60 | 60 |
| 61 ExtensionPopupGtk::~ExtensionPopupGtk() { | 61 ExtensionPopupGtk::~ExtensionPopupGtk() { |
| 62 } | 62 } |
| 63 | 63 |
| 64 void ExtensionPopupGtk::Observe(NotificationType type, | 64 void ExtensionPopupGtk::Observe(int type, |
| 65 const NotificationSource& source, | 65 const NotificationSource& source, |
| 66 const NotificationDetails& details) { | 66 const NotificationDetails& details) { |
| 67 switch (type.value) { | 67 switch (type) { |
| 68 case NotificationType::EXTENSION_HOST_DID_STOP_LOADING: | 68 case chrome::EXTENSION_HOST_DID_STOP_LOADING: |
| 69 if (Details<ExtensionHost>(host_.get()) == details) | 69 if (Details<ExtensionHost>(host_.get()) == details) |
| 70 ShowPopup(); | 70 ShowPopup(); |
| 71 break; | 71 break; |
| 72 case NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE: | 72 case chrome::EXTENSION_HOST_VIEW_SHOULD_CLOSE: |
| 73 if (Details<ExtensionHost>(host_.get()) == details) | 73 if (Details<ExtensionHost>(host_.get()) == details) |
| 74 DestroyPopup(); | 74 DestroyPopup(); |
| 75 break; | 75 break; |
| 76 case NotificationType::DEVTOOLS_WINDOW_CLOSING: | 76 case chrome::DEVTOOLS_WINDOW_CLOSING: |
| 77 // Make sure its the devtools window that inspecting our popup. | 77 // Make sure its the devtools window that inspecting our popup. |
| 78 if (Details<RenderViewHost>(host_->render_view_host()) != details) | 78 if (Details<RenderViewHost>(host_->render_view_host()) != details) |
| 79 break; | 79 break; |
| 80 | 80 |
| 81 // If the devtools window is closing, we post a task to ourselves to | 81 // If the devtools window is closing, we post a task to ourselves to |
| 82 // close the popup. This gives the devtools window a chance to finish | 82 // close the popup. This gives the devtools window a chance to finish |
| 83 // detaching from the inspected RenderViewHost. | 83 // detaching from the inspected RenderViewHost. |
| 84 MessageLoop::current()->PostTask(FROM_HERE, | 84 MessageLoop::current()->PostTask(FROM_HERE, |
| 85 method_factory_.NewRunnableMethod(&ExtensionPopupGtk::DestroyPopup)); | 85 method_factory_.NewRunnableMethod(&ExtensionPopupGtk::DestroyPopup)); |
| 86 break; | 86 break; |
| 87 default: | 87 default: |
| 88 NOTREACHED() << "Received unexpected notification"; | 88 NOTREACHED() << "Received unexpected notification"; |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 void ExtensionPopupGtk::ShowPopup() { | 92 void ExtensionPopupGtk::ShowPopup() { |
| 93 if (bubble_) { | 93 if (bubble_) { |
| 94 NOTREACHED(); | 94 NOTREACHED(); |
| 95 return; | 95 return; |
| 96 } | 96 } |
| 97 | 97 |
| 98 if (being_inspected_) { | 98 if (being_inspected_) { |
| 99 DevToolsWindow::OpenDevToolsWindow(host_->render_view_host()); | 99 DevToolsWindow::OpenDevToolsWindow(host_->render_view_host()); |
| 100 // Listen for the the devtools window closing. | 100 // Listen for the the devtools window closing. |
| 101 registrar_.Add(this, NotificationType::DEVTOOLS_WINDOW_CLOSING, | 101 registrar_.Add(this, chrome::DEVTOOLS_WINDOW_CLOSING, |
| 102 Source<Profile>(host_->profile())); | 102 Source<Profile>(host_->profile())); |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Only one instance should be showing at a time. Get rid of the old one, if | 105 // Only one instance should be showing at a time. Get rid of the old one, if |
| 106 // any. Typically, |current_extension_popup_| will be NULL, but it can be | 106 // any. Typically, |current_extension_popup_| will be NULL, but it can be |
| 107 // non-NULL if a browser action button is clicked while another extension | 107 // non-NULL if a browser action button is clicked while another extension |
| 108 // popup's extension host is still loading. | 108 // popup's extension host is still loading. |
| 109 if (current_extension_popup_) | 109 if (current_extension_popup_) |
| 110 current_extension_popup_->DestroyPopup(); | 110 current_extension_popup_->DestroyPopup(); |
| 111 current_extension_popup_ = this; | 111 current_extension_popup_ = this; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 return; | 163 return; |
| 164 | 164 |
| 165 ExtensionHost* host = manager->CreatePopupHost(url, browser); | 165 ExtensionHost* host = manager->CreatePopupHost(url, browser); |
| 166 // This object will delete itself when the bubble is closed. | 166 // This object will delete itself when the bubble is closed. |
| 167 new ExtensionPopupGtk(browser, host, anchor, inspect); | 167 new ExtensionPopupGtk(browser, host, anchor, inspect); |
| 168 } | 168 } |
| 169 | 169 |
| 170 gfx::Rect ExtensionPopupGtk::GetViewBounds() { | 170 gfx::Rect ExtensionPopupGtk::GetViewBounds() { |
| 171 return gfx::Rect(host_->view()->native_view()->allocation); | 171 return gfx::Rect(host_->view()->native_view()->allocation); |
| 172 } | 172 } |
| OLD | NEW |