| 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/views/collected_cookies_win.h" | 5 #include "chrome/browser/ui/views/collected_cookies_win.h" |
| 6 | 6 |
| 7 #include "chrome/browser/content_settings/host_content_settings_map.h" | 7 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 9 #include "chrome/browser/cookies_tree_model.h" | 9 #include "chrome/browser/cookies_tree_model.h" |
| 10 #include "chrome/browser/infobars/infobar_tab_helper.h" | 10 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "views/controls/tabbed_pane/tabbed_pane.h" | 29 #include "views/controls/tabbed_pane/tabbed_pane.h" |
| 30 #include "views/layout/box_layout.h" | 30 #include "views/layout/box_layout.h" |
| 31 #include "views/layout/grid_layout.h" | 31 #include "views/layout/grid_layout.h" |
| 32 #include "views/layout/layout_constants.h" | 32 #include "views/layout/layout_constants.h" |
| 33 #include "views/widget/widget.h" | 33 #include "views/widget/widget.h" |
| 34 | 34 |
| 35 namespace browser { | 35 namespace browser { |
| 36 | 36 |
| 37 // Declared in browser_dialogs.h so others don't have to depend on our header. | 37 // Declared in browser_dialogs.h so others don't have to depend on our header. |
| 38 void ShowCollectedCookiesDialog(gfx::NativeWindow parent_window, | 38 void ShowCollectedCookiesDialog(gfx::NativeWindow parent_window, |
| 39 TabContents* tab_contents) { | 39 TabContentsWrapper* wrapper) { |
| 40 // Deletes itself on close. | 40 // Deletes itself on close. |
| 41 new CollectedCookiesWin(parent_window, tab_contents); | 41 new CollectedCookiesWin(parent_window, wrapper); |
| 42 } | 42 } |
| 43 | 43 |
| 44 } // namespace browser | 44 } // namespace browser |
| 45 | 45 |
| 46 namespace { | 46 namespace { |
| 47 // Spacing between the infobar frame and its contents. | 47 // Spacing between the infobar frame and its contents. |
| 48 const int kInfobarVerticalPadding = 3; | 48 const int kInfobarVerticalPadding = 3; |
| 49 const int kInfobarHorizontalPadding = 8; | 49 const int kInfobarHorizontalPadding = 8; |
| 50 | 50 |
| 51 // Width of the infobar frame. | 51 // Width of the infobar frame. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 // The label responsible for rendering the text. | 157 // The label responsible for rendering the text. |
| 158 views::Label* label_; | 158 views::Label* label_; |
| 159 | 159 |
| 160 DISALLOW_COPY_AND_ASSIGN(InfobarView); | 160 DISALLOW_COPY_AND_ASSIGN(InfobarView); |
| 161 }; | 161 }; |
| 162 | 162 |
| 163 /////////////////////////////////////////////////////////////////////////////// | 163 /////////////////////////////////////////////////////////////////////////////// |
| 164 // CollectedCookiesWin, constructor and destructor: | 164 // CollectedCookiesWin, constructor and destructor: |
| 165 | 165 |
| 166 CollectedCookiesWin::CollectedCookiesWin(gfx::NativeWindow parent_window, | 166 CollectedCookiesWin::CollectedCookiesWin(gfx::NativeWindow parent_window, |
| 167 TabContents* tab_contents) | 167 TabContentsWrapper* wrapper) |
| 168 : tab_contents_(tab_contents), | 168 : wrapper_(wrapper), |
| 169 allowed_label_(NULL), | 169 allowed_label_(NULL), |
| 170 blocked_label_(NULL), | 170 blocked_label_(NULL), |
| 171 allowed_cookies_tree_(NULL), | 171 allowed_cookies_tree_(NULL), |
| 172 blocked_cookies_tree_(NULL), | 172 blocked_cookies_tree_(NULL), |
| 173 block_allowed_button_(NULL), | 173 block_allowed_button_(NULL), |
| 174 allow_blocked_button_(NULL), | 174 allow_blocked_button_(NULL), |
| 175 for_session_blocked_button_(NULL), | 175 for_session_blocked_button_(NULL), |
| 176 infobar_(NULL), | 176 infobar_(NULL), |
| 177 status_changed_(false) { | 177 status_changed_(false) { |
| 178 TabSpecificContentSettings* content_settings = | 178 TabSpecificContentSettings* content_settings = wrapper->content_settings(); |
| 179 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents)-> | |
| 180 content_settings(); | |
| 181 registrar_.Add(this, chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, | 179 registrar_.Add(this, chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, |
| 182 Source<TabSpecificContentSettings>(content_settings)); | 180 Source<TabSpecificContentSettings>(content_settings)); |
| 183 | 181 |
| 184 Init(); | 182 Init(); |
| 185 | 183 |
| 186 window_ = new ConstrainedWindowViews(tab_contents_, this); | 184 window_ = new ConstrainedWindowViews(wrapper->tab_contents(), this); |
| 187 } | 185 } |
| 188 | 186 |
| 189 CollectedCookiesWin::~CollectedCookiesWin() { | 187 CollectedCookiesWin::~CollectedCookiesWin() { |
| 190 allowed_cookies_tree_->SetModel(NULL); | 188 allowed_cookies_tree_->SetModel(NULL); |
| 191 blocked_cookies_tree_->SetModel(NULL); | 189 blocked_cookies_tree_->SetModel(NULL); |
| 192 } | 190 } |
| 193 | 191 |
| 194 void CollectedCookiesWin::Init() { | 192 void CollectedCookiesWin::Init() { |
| 195 using views::GridLayout; | 193 using views::GridLayout; |
| 196 | 194 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 229 |
| 232 layout->StartRow(0, single_column_with_padding_layout_id); | 230 layout->StartRow(0, single_column_with_padding_layout_id); |
| 233 infobar_ = new InfobarView(); | 231 infobar_ = new InfobarView(); |
| 234 layout->AddView(infobar_); | 232 layout->AddView(infobar_); |
| 235 | 233 |
| 236 EnableControls(); | 234 EnableControls(); |
| 237 ShowCookieInfo(); | 235 ShowCookieInfo(); |
| 238 } | 236 } |
| 239 | 237 |
| 240 views::View* CollectedCookiesWin::CreateAllowedPane() { | 238 views::View* CollectedCookiesWin::CreateAllowedPane() { |
| 241 TabSpecificContentSettings* content_settings = | 239 TabSpecificContentSettings* content_settings = wrapper_->content_settings(); |
| 242 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_)-> | |
| 243 content_settings(); | |
| 244 | 240 |
| 245 // Create the controls that go into the pane. | 241 // Create the controls that go into the pane. |
| 246 allowed_label_ = new views::Label(UTF16ToWide(l10n_util::GetStringUTF16( | 242 allowed_label_ = new views::Label(UTF16ToWide(l10n_util::GetStringUTF16( |
| 247 IDS_COLLECTED_COOKIES_ALLOWED_COOKIES_LABEL))); | 243 IDS_COLLECTED_COOKIES_ALLOWED_COOKIES_LABEL))); |
| 248 allowed_cookies_tree_model_.reset( | 244 allowed_cookies_tree_model_.reset( |
| 249 content_settings->GetAllowedCookiesTreeModel()); | 245 content_settings->GetAllowedCookiesTreeModel()); |
| 250 allowed_cookies_tree_ = new views::TreeView(); | 246 allowed_cookies_tree_ = new views::TreeView(); |
| 251 allowed_cookies_tree_->SetModel(allowed_cookies_tree_model_.get()); | 247 allowed_cookies_tree_->SetModel(allowed_cookies_tree_model_.get()); |
| 252 allowed_cookies_tree_->SetController(this); | 248 allowed_cookies_tree_->SetController(this); |
| 253 allowed_cookies_tree_->SetRootShown(false); | 249 allowed_cookies_tree_->SetRootShown(false); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 281 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 277 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 282 | 278 |
| 283 layout->StartRow(0, single_column_layout_id); | 279 layout->StartRow(0, single_column_layout_id); |
| 284 layout->AddView(block_allowed_button_, 1, 1, GridLayout::LEADING, | 280 layout->AddView(block_allowed_button_, 1, 1, GridLayout::LEADING, |
| 285 GridLayout::CENTER); | 281 GridLayout::CENTER); |
| 286 | 282 |
| 287 return pane; | 283 return pane; |
| 288 } | 284 } |
| 289 | 285 |
| 290 views::View* CollectedCookiesWin::CreateBlockedPane() { | 286 views::View* CollectedCookiesWin::CreateBlockedPane() { |
| 291 TabContentsWrapper* wrapper = | 287 TabSpecificContentSettings* content_settings = wrapper_->content_settings(); |
| 292 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_); | |
| 293 TabSpecificContentSettings* content_settings = wrapper->content_settings(); | |
| 294 | 288 |
| 295 HostContentSettingsMap* host_content_settings_map = | 289 HostContentSettingsMap* host_content_settings_map = |
| 296 wrapper->profile()->GetHostContentSettingsMap(); | 290 wrapper_->profile()->GetHostContentSettingsMap(); |
| 297 | 291 |
| 298 // Create the controls that go into the pane. | 292 // Create the controls that go into the pane. |
| 299 blocked_label_ = new views::Label( | 293 blocked_label_ = new views::Label( |
| 300 UTF16ToWide(l10n_util::GetStringUTF16( | 294 UTF16ToWide(l10n_util::GetStringUTF16( |
| 301 host_content_settings_map->BlockThirdPartyCookies() ? | 295 host_content_settings_map->BlockThirdPartyCookies() ? |
| 302 IDS_COLLECTED_COOKIES_BLOCKED_THIRD_PARTY_BLOCKING_ENABLED : | 296 IDS_COLLECTED_COOKIES_BLOCKED_THIRD_PARTY_BLOCKING_ENABLED : |
| 303 IDS_COLLECTED_COOKIES_BLOCKED_COOKIES_LABEL))); | 297 IDS_COLLECTED_COOKIES_BLOCKED_COOKIES_LABEL))); |
| 304 blocked_label_->SetMultiLine(true); | 298 blocked_label_->SetMultiLine(true); |
| 305 blocked_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 299 blocked_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 306 blocked_cookies_tree_model_.reset( | 300 blocked_cookies_tree_model_.reset( |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 MessageBoxFlags::DialogButton button) const { | 366 MessageBoxFlags::DialogButton button) const { |
| 373 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CLOSE)); | 367 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CLOSE)); |
| 374 } | 368 } |
| 375 | 369 |
| 376 void CollectedCookiesWin::DeleteDelegate() { | 370 void CollectedCookiesWin::DeleteDelegate() { |
| 377 delete this; | 371 delete this; |
| 378 } | 372 } |
| 379 | 373 |
| 380 bool CollectedCookiesWin::Cancel() { | 374 bool CollectedCookiesWin::Cancel() { |
| 381 if (status_changed_) { | 375 if (status_changed_) { |
| 382 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_)-> | 376 wrapper_->infobar_tab_helper()->AddInfoBar( |
| 383 infobar_tab_helper()->AddInfoBar( | 377 new CollectedCookiesInfoBarDelegate(wrapper_->tab_contents())); |
| 384 new CollectedCookiesInfoBarDelegate(tab_contents_)); | |
| 385 } | 378 } |
| 386 | 379 |
| 387 return true; | 380 return true; |
| 388 } | 381 } |
| 389 | 382 |
| 390 views::View* CollectedCookiesWin::GetContentsView() { | 383 views::View* CollectedCookiesWin::GetContentsView() { |
| 391 return this; | 384 return this; |
| 392 } | 385 } |
| 393 | 386 |
| 394 views::Widget* CollectedCookiesWin::GetWidget() { | 387 views::Widget* CollectedCookiesWin::GetWidget() { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 } | 472 } |
| 480 } else { | 473 } else { |
| 481 cookie_info_view_->ClearCookieDisplay(); | 474 cookie_info_view_->ClearCookieDisplay(); |
| 482 } | 475 } |
| 483 } | 476 } |
| 484 | 477 |
| 485 void CollectedCookiesWin::AddContentException(views::TreeView* tree_view, | 478 void CollectedCookiesWin::AddContentException(views::TreeView* tree_view, |
| 486 ContentSetting setting) { | 479 ContentSetting setting) { |
| 487 CookieTreeOriginNode* origin_node = | 480 CookieTreeOriginNode* origin_node = |
| 488 static_cast<CookieTreeOriginNode*>(tree_view->GetSelectedNode()); | 481 static_cast<CookieTreeOriginNode*>(tree_view->GetSelectedNode()); |
| 489 Profile* profile = | 482 Profile* profile = wrapper_->profile(); |
| 490 Profile::FromBrowserContext(tab_contents_->browser_context()); | |
| 491 origin_node->CreateContentException(profile->GetHostContentSettingsMap(), | 483 origin_node->CreateContentException(profile->GetHostContentSettingsMap(), |
| 492 setting); | 484 setting); |
| 493 infobar_->UpdateVisibility(true, setting, origin_node->GetTitle()); | 485 infobar_->UpdateVisibility(true, setting, origin_node->GetTitle()); |
| 494 gfx::Rect bounds = GetWidget()->GetClientAreaScreenBounds(); | 486 gfx::Rect bounds = GetWidget()->GetClientAreaScreenBounds(); |
| 495 // NativeWidgetWin::GetBounds returns the bounds relative to the parent | 487 // NativeWidgetWin::GetBounds returns the bounds relative to the parent |
| 496 // window, while NativeWidgetWin::SetBounds wants screen coordinates. Do the | 488 // window, while NativeWidgetWin::SetBounds wants screen coordinates. Do the |
| 497 // translation here until http://crbug.com/52851 is fixed. | 489 // translation here until http://crbug.com/52851 is fixed. |
| 498 POINT topleft = {bounds.x(), bounds.y()}; | 490 POINT topleft = {bounds.x(), bounds.y()}; |
| 499 MapWindowPoints(HWND_DESKTOP, tab_contents_->GetNativeView(), &topleft, 1); | 491 MapWindowPoints(HWND_DESKTOP, wrapper_->tab_contents()->GetNativeView(), |
| 492 &topleft, 1); |
| 500 gfx::Size size = GetWidget()->GetRootView()->GetPreferredSize(); | 493 gfx::Size size = GetWidget()->GetRootView()->GetPreferredSize(); |
| 501 bounds.SetRect(topleft.x, topleft.y, size.width(), size.height()); | 494 bounds.SetRect(topleft.x, topleft.y, size.width(), size.height()); |
| 502 GetWidget()->SetBounds(bounds); | 495 GetWidget()->SetBounds(bounds); |
| 503 status_changed_ = true; | 496 status_changed_ = true; |
| 504 } | 497 } |
| 505 | 498 |
| 506 /////////////////////////////////////////////////////////////////////////////// | 499 /////////////////////////////////////////////////////////////////////////////// |
| 507 // NotificationObserver implementation. | 500 // NotificationObserver implementation. |
| 508 | 501 |
| 509 void CollectedCookiesWin::Observe(int type, | 502 void CollectedCookiesWin::Observe(int type, |
| 510 const NotificationSource& source, | 503 const NotificationSource& source, |
| 511 const NotificationDetails& details) { | 504 const NotificationDetails& details) { |
| 512 DCHECK(type == chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN); | 505 DCHECK(type == chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN); |
| 513 window_->CloseConstrainedWindow(); | 506 window_->CloseConstrainedWindow(); |
| 514 } | 507 } |
| OLD | NEW |