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

Side by Side Diff: chrome/browser/gtk/notifications/balloon_view_host_gtk.cc

Issue 1055005: Refactor BalloonViewHost, removing a lot of duplicate code that crept into no... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 10 years, 9 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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/gtk/notifications/balloon_view_host_gtk.h" 5 #include "chrome/browser/gtk/notifications/balloon_view_host_gtk.h"
6 6
7 #include "base/string_util.h"
8 #include "chrome/browser/browser_list.h"
9 #include "chrome/browser/in_process_webkit/dom_storage_context.h"
10 #include "chrome/browser/in_process_webkit/webkit_context.h"
11 #include "chrome/browser/notifications/balloon.h" 7 #include "chrome/browser/notifications/balloon.h"
12 #include "chrome/browser/notifications/notification.h"
13 #include "chrome/browser/profile.h"
14 #include "chrome/browser/renderer_host/render_view_host.h" 8 #include "chrome/browser/renderer_host/render_view_host.h"
15 #include "chrome/browser/renderer_host/render_widget_host_view.h" 9 #include "chrome/browser/renderer_host/render_widget_host_view.h"
16 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" 10 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h"
17 #include "chrome/browser/renderer_host/site_instance.h"
18 #include "chrome/browser/renderer_preferences_util.h"
19 #include "chrome/common/notification_service.h"
20 #include "chrome/common/notification_type.h"
21 #include "chrome/common/render_messages.h"
22 #include "chrome/common/renderer_preferences.h"
23 11
24 BalloonViewHost::BalloonViewHost(Balloon* balloon) 12 BalloonViewHost::BalloonViewHost(Balloon* balloon)
25 : initialized_(false), 13 : BalloonHost(balloon) {
26 balloon_(balloon),
27 site_instance_(SiteInstance::CreateSiteInstance(balloon->profile())),
28 render_view_host_(NULL),
29 should_notify_on_disconnect_(false) {
30 DCHECK(balloon_);
31 }
32
33 void BalloonViewHost::Shutdown() {
34 if (render_view_host_) {
35 render_view_host_->Shutdown();
36 render_view_host_ = NULL;
37 }
38 }
39
40 WebPreferences BalloonViewHost::GetWebkitPrefs() {
41 WebPreferences prefs;
42 prefs.allow_scripts_to_close_windows = true;
43 return prefs;
44 }
45
46 RendererPreferences BalloonViewHost::GetRendererPrefs(Profile* profile) const {
47 RendererPreferences prefs;
48 renderer_preferences_util::UpdateFromSystemSettings(&prefs, profile);
49 // We want links (a.k.a. top_level_requests) to be forwarded to the browser so
50 // that we can open them in a new tab rather than in the balloon.
51 prefs.browser_handles_top_level_requests = true;
52 return prefs;
53 }
54
55 void BalloonViewHost::RequestOpenURL(const GURL& url,
56 const GURL& referrer,
57 WindowOpenDisposition disposition) {
58 // Always open a link triggered within the notification balloon in a new tab.
59 // TODO(johnnyg): this new tab should always be in the same workspace as the
60 // notification.
61 BrowserList::GetLastActive()->AddTabWithURL(url, referrer,
62 PageTransition::LINK, true, 0, 0, GetSiteInstance());
63 }
64
65 void BalloonViewHost::Close(RenderViewHost* render_view_host) {
66 balloon_->CloseByScript();
67 }
68
69 void BalloonViewHost::RenderViewCreated(RenderViewHost* render_view_host) {
70 render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode(
71 render_view_host->routing_id()));
72 }
73
74 void BalloonViewHost::RendererReady(RenderViewHost* render_view_host) {
75 should_notify_on_disconnect_ = true;
76 NotificationService::current()->Notify(
77 NotificationType::NOTIFY_BALLOON_CONNECTED,
78 Source<Balloon>(balloon_), NotificationService::NoDetails());
79 }
80
81 void BalloonViewHost::RendererGone(RenderViewHost* render_view_host) {
82 if (!should_notify_on_disconnect_)
83 return;
84
85 should_notify_on_disconnect_ = false;
86 NotificationService::current()->Notify(
87 NotificationType::NOTIFY_BALLOON_DISCONNECTED,
88 Source<Balloon>(balloon_), NotificationService::NoDetails());
89 }
90
91 // RenderViewHostDelegate::View methods implemented to allow links to
92 // open pages in new tabs.
93 void BalloonViewHost::CreateNewWindow(int route_id) {
94 delegate_view_helper_.CreateNewWindow(
95 route_id, balloon_->profile(), site_instance_.get(),
96 DOMUIFactory::GetDOMUIType(balloon_->notification().content_url()), NULL);
97 }
98
99 void BalloonViewHost::ShowCreatedWindow(int route_id,
100 WindowOpenDisposition disposition,
101 const gfx::Rect& initial_pos,
102 bool user_gesture) {
103 // Don't allow pop-ups from notifications.
104 if (disposition == NEW_POPUP)
105 return;
106
107 TabContents* contents = delegate_view_helper_.GetCreatedWindow(route_id);
108 if (contents) {
109 Browser* browser = BrowserList::GetLastActive();
110 browser->AddTabContents(contents, disposition, initial_pos, user_gesture);
111 }
112 }
113
114 void BalloonViewHost::UpdatePreferredSize(const gfx::Size& new_size) {
115 balloon_->SetContentPreferredSize(new_size);
116 } 14 }
117 15
118 void BalloonViewHost::UpdateActualSize(const gfx::Size& new_size) { 16 void BalloonViewHost::UpdateActualSize(const gfx::Size& new_size) {
119 render_widget_host_view_->SetSize(new_size); 17 render_widget_host_view_->SetSize(new_size);
120 // gfx::Size(new_size.width(), new_size.height()));
121 gtk_widget_set_size_request( 18 gtk_widget_set_size_request(
122 native_view(), new_size.width(), new_size.height()); 19 native_view(), new_size.width(), new_size.height());
123 } 20 }
124 21
125 void BalloonViewHost::Init() { 22 gfx::NativeView BalloonViewHost::native_view() const {
126 DCHECK(!render_view_host_) << "BalloonViewHost already initialized."; 23 return render_widget_host_view_->native_view();
24 }
127 25
128 int64 session_storage_namespace_id = balloon_->profile()->GetWebKitContext()-> 26 void BalloonViewHost::InitRenderWidgetHostView() {
129 dom_storage_context()->AllocateSessionStorageNamespaceId(); 27 DCHECK(render_view_host_);
130
131 render_view_host_ = new RenderViewHost(site_instance_.get(),
132 this, MSG_ROUTING_NONE,
133 session_storage_namespace_id);
134
135 render_widget_host_view_ = new RenderWidgetHostViewGtk(render_view_host_); 28 render_widget_host_view_ = new RenderWidgetHostViewGtk(render_view_host_);
136 render_widget_host_view_->InitAsChild(); 29 render_widget_host_view_->InitAsChild();
30 }
137 31
138 render_view_host_->set_view(render_widget_host_view_); 32 RenderWidgetHostView* BalloonViewHost::render_widget_host_view() const {
139 render_view_host_->CreateRenderView(GetProfile()->GetRequestContext()); 33 return render_widget_host_view_;
140 render_view_host_->NavigateToURL(balloon_->notification().content_url());
141 initialized_ = true;
142 } 34 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/notifications/balloon_view_host_gtk.h ('k') | chrome/browser/notifications/balloon_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698