| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/extensions/extension_view.h" | 5 #include "chrome/browser/extensions/extension_view.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/browser.h" | 8 #include "chrome/browser/browser.h" |
| 9 #include "chrome/browser/character_encoding.h" | 9 #include "chrome/browser/character_encoding.h" |
| 10 #include "chrome/browser/extensions/extension.h" | 10 #include "chrome/browser/extensions/extension.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 28 | 28 |
| 29 #include "webkit/glue/context_menu.h" | 29 #include "webkit/glue/context_menu.h" |
| 30 | 30 |
| 31 ExtensionView::ExtensionView(Extension* extension, | 31 ExtensionView::ExtensionView(Extension* extension, |
| 32 const GURL& url, | 32 const GURL& url, |
| 33 SiteInstance* instance, | 33 SiteInstance* instance, |
| 34 Browser* browser) | 34 Browser* browser) |
| 35 : HWNDHtmlView(url, this, false, instance), | 35 : HWNDHtmlView(url, this, false, instance), |
| 36 extension_(extension), | 36 extension_(extension), |
| 37 browser_(browser) { | 37 browser_(browser), |
| 38 SetVisible(false); | 38 did_stop_loading_(false), |
| 39 pending_preferred_width_(0) { |
| 40 } |
| 41 |
| 42 void ExtensionView::ShowIfCompletelyLoaded() { |
| 43 // We wait to show the ExtensionView until it has loaded and our parent has |
| 44 // given us a background. These can happen in different orders. |
| 45 if (did_stop_loading_ && !render_view_host()->view()->background().empty()) { |
| 46 SetVisible(true); |
| 47 DidContentsPreferredWidthChange(pending_preferred_width_); |
| 48 } |
| 49 } |
| 50 |
| 51 void ExtensionView::SetBackground(const SkBitmap& background) { |
| 52 HWNDHtmlView::SetBackground(background); |
| 53 ShowIfCompletelyLoaded(); |
| 39 } | 54 } |
| 40 | 55 |
| 41 void ExtensionView::DidStopLoading(RenderViewHost* render_view_host, | 56 void ExtensionView::DidStopLoading(RenderViewHost* render_view_host, |
| 42 int32 page_id) { | 57 int32 page_id) { |
| 43 render_view_host->WasResized(); | 58 render_view_host->WasResized(); |
| 44 SetVisible(true); | 59 did_stop_loading_ = true; |
| 60 ShowIfCompletelyLoaded(); |
| 45 } | 61 } |
| 46 | 62 |
| 47 void ExtensionView::DidContentsPreferredWidthChange(const int pref_width) { | 63 void ExtensionView::DidContentsPreferredWidthChange(const int pref_width) { |
| 48 if (pref_width > 0) { | 64 // Don't actually do anything with this information until we have been shown. |
| 49 // SchedulePaint first because new_width may be smaller and we want | 65 // Size changes will not be honored by lower layers while we are hidden. |
| 50 // the Parent to paint the vacated space. | 66 if (!IsVisible()) { |
| 51 SchedulePaint(); | 67 pending_preferred_width_ = pref_width; |
| 68 } else if (pref_width > 0) { |
| 52 set_preferred_size(gfx::Size(pref_width, height())); | 69 set_preferred_size(gfx::Size(pref_width, height())); |
| 53 SizeToPreferredSize(); | 70 SizeToPreferredSize(); |
| 54 | 71 |
| 55 // TODO(rafaelw): This assumes that the extension view is a child of an | 72 // TODO(rafaelw): This assumes that the extension view is a child of an |
| 56 // ExtensionToolstrip, which is a child of the BookmarkBarView. There should | 73 // ExtensionToolstrip, which is a child of the BookmarkBarView. There should |
| 57 // be a way to do this where the ExtensionView doesn't have to know it's | 74 // be a way to do this where the ExtensionView doesn't have to know it's |
| 58 // containment hierarchy. | 75 // containment hierarchy. |
| 59 if (GetParent() != NULL && GetParent()->GetParent() != NULL) { | 76 if (GetParent() != NULL && GetParent()->GetParent() != NULL) { |
| 60 GetParent()->GetParent()->Layout(); | 77 GetParent()->GetParent()->Layout(); |
| 61 } | 78 } |
| 62 | 79 |
| 63 SchedulePaint(); | 80 SchedulePaint(); |
| 64 render_view_host()->WasResized(); | |
| 65 } | 81 } |
| 66 } | 82 } |
| 67 | 83 |
| 68 void ExtensionView::CreatingRenderer() { | 84 void ExtensionView::CreatingRenderer() { |
| 69 render_view_host()->AllowExtensionBindings(); | 85 render_view_host()->AllowExtensionBindings(); |
| 86 SetVisible(false); |
| 70 } | 87 } |
| 71 | 88 |
| 72 void ExtensionView::RenderViewCreated(RenderViewHost* rvh) { | 89 void ExtensionView::RenderViewCreated(RenderViewHost* rvh) { |
| 73 URLRequestContext* context = rvh->process()->profile()->GetRequestContext(); | 90 URLRequestContext* context = rvh->process()->profile()->GetRequestContext(); |
| 74 ExtensionMessageService::GetInstance(context)->RegisterExtension( | 91 ExtensionMessageService::GetInstance(context)->RegisterExtension( |
| 75 extension_->id(), render_view_host()->process()->pid()); | 92 extension_->id(), render_view_host()->process()->pid()); |
| 76 } | 93 } |
| 77 | 94 |
| 78 WebPreferences ExtensionView::GetWebkitPrefs() { | 95 WebPreferences ExtensionView::GetWebkitPrefs() { |
| 79 PrefService* prefs = render_view_host()->process()->profile()->GetPrefs(); | 96 PrefService* prefs = render_view_host()->process()->profile()->GetPrefs(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 169 } |
| 153 | 170 |
| 154 void ExtensionView::UpdateDragCursor(bool is_drop_target) { | 171 void ExtensionView::UpdateDragCursor(bool is_drop_target) { |
| 155 } | 172 } |
| 156 | 173 |
| 157 void ExtensionView::TakeFocus(bool reverse) { | 174 void ExtensionView::TakeFocus(bool reverse) { |
| 158 } | 175 } |
| 159 | 176 |
| 160 void ExtensionView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { | 177 void ExtensionView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
| 161 } | 178 } |
| OLD | NEW |