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

Side by Side Diff: chrome/browser/content_settings/tab_specific_content_settings.h

Issue 87853004: Refactoring Manage Passwords Bubble Code to exclude TabSpecificContentSettings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@movingclasses
Patch Set: adding controller files Created 7 years 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
OLDNEW
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 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_TAB_SPECIFIC_CONTENT_SETTINGS_H_ 5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_TAB_SPECIFIC_CONTENT_SETTINGS_H_
6 #define CHROME_BROWSER_CONTENT_SETTINGS_TAB_SPECIFIC_CONTENT_SETTINGS_H_ 6 #define CHROME_BROWSER_CONTENT_SETTINGS_TAB_SPECIFIC_CONTENT_SETTINGS_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h" 14 #include "base/observer_list.h"
15 #include "chrome/browser/content_settings/content_settings_usages_state.h" 15 #include "chrome/browser/content_settings/content_settings_usages_state.h"
16 #include "chrome/browser/content_settings/local_shared_objects_container.h" 16 #include "chrome/browser/content_settings/local_shared_objects_container.h"
17 #include "chrome/browser/media/media_stream_devices_controller.h" 17 #include "chrome/browser/media/media_stream_devices_controller.h"
18 #include "chrome/browser/password_manager/password_form_manager.h"
19 #include "chrome/common/content_settings.h" 18 #include "chrome/common/content_settings.h"
20 #include "chrome/common/content_settings_types.h" 19 #include "chrome/common/content_settings_types.h"
21 #include "chrome/common/custom_handlers/protocol_handler.h" 20 #include "chrome/common/custom_handlers/protocol_handler.h"
22 #include "content/public/browser/notification_observer.h" 21 #include "content/public/browser/notification_observer.h"
23 #include "content/public/browser/notification_registrar.h" 22 #include "content/public/browser/notification_registrar.h"
24 #include "content/public/browser/web_contents_observer.h" 23 #include "content/public/browser/web_contents_observer.h"
25 #include "content/public/browser/web_contents_user_data.h" 24 #include "content/public/browser/web_contents_user_data.h"
26 #include "content/public/common/media_stream_request.h" 25 #include "content/public/common/media_stream_request.h"
27 #include "net/cookies/canonical_cookie.h" 26 #include "net/cookies/canonical_cookie.h"
28 27
(...skipping 20 matching lines...) Expand all
49 enum MicrophoneCameraState { 48 enum MicrophoneCameraState {
50 MICROPHONE_CAMERA_NOT_ACCESSED = 0, 49 MICROPHONE_CAMERA_NOT_ACCESSED = 0,
51 MICROPHONE_ACCESSED, 50 MICROPHONE_ACCESSED,
52 CAMERA_ACCESSED, 51 CAMERA_ACCESSED,
53 MICROPHONE_CAMERA_ACCESSED, 52 MICROPHONE_CAMERA_ACCESSED,
54 MICROPHONE_BLOCKED, 53 MICROPHONE_BLOCKED,
55 CAMERA_BLOCKED, 54 CAMERA_BLOCKED,
56 MICROPHONE_CAMERA_BLOCKED, 55 MICROPHONE_CAMERA_BLOCKED,
57 }; 56 };
58 57
59 // A PasswordObserver is implemented in ManagePasswordsIconController which
60 // will be notified when a password form is submitted.
61 class PasswordObserver {
62 public:
63 explicit PasswordObserver(
64 TabSpecificContentSettings* tab_specific_content_settings);
65 virtual ~PasswordObserver();
66
67 // Called whenever a password form is submitted.
68 virtual void OnPasswordAction() = 0;
69
70 TabSpecificContentSettings* tab_specific_content_settings() {
71 return tab_specific_content_settings_;
72 }
73
74 // Called when the TabSpecificContentSettings is destroyed; nulls out
75 // the local reference.
76 void ContentSettingsDestroyed();
77
78 private:
79 TabSpecificContentSettings* tab_specific_content_settings_;
80
81 DISALLOW_COPY_AND_ASSIGN(PasswordObserver);
82 };
83
84 // Classes that want to be notified about site data events must implement 58 // Classes that want to be notified about site data events must implement
85 // this abstract class and add themselves as observer to the 59 // this abstract class and add themselves as observer to the
86 // |TabSpecificContentSettings|. 60 // |TabSpecificContentSettings|.
87 class SiteDataObserver { 61 class SiteDataObserver {
88 public: 62 public:
89 explicit SiteDataObserver( 63 explicit SiteDataObserver(
90 TabSpecificContentSettings* tab_specific_content_settings); 64 TabSpecificContentSettings* tab_specific_content_settings);
91 virtual ~SiteDataObserver(); 65 virtual ~SiteDataObserver();
92 66
93 // Called whenever site data is accessed. 67 // Called whenever site data is accessed.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 return media_stream_requested_audio_device_; 198 return media_stream_requested_audio_device_;
225 } 199 }
226 200
227 const std::string& media_stream_requested_video_device() const { 201 const std::string& media_stream_requested_video_device() const {
228 return media_stream_requested_video_device_; 202 return media_stream_requested_video_device_;
229 } 203 }
230 204
231 // Returns the state of the camera and microphone usage. 205 // Returns the state of the camera and microphone usage.
232 MicrophoneCameraState GetMicrophoneCameraState() const; 206 MicrophoneCameraState GetMicrophoneCameraState() const;
233 207
234 void unset_manage_passwords_bubble_needs_showing() {
235 manage_passwords_bubble_needs_showing_ = false;
236 }
237
238 bool password_to_be_saved() const {
239 return password_to_be_saved_;
240 }
241
242 void unset_password_to_be_saved() {
243 password_to_be_saved_ = false;
244 }
245
246 bool manage_passwords_bubble_needs_showing() const {
247 return manage_passwords_bubble_needs_showing_;
248 }
249
250 bool manage_passwords_icon_to_be_shown() const {
251 return manage_passwords_icon_to_be_shown_;
252 }
253
254 // Returns whether there is a password to be saved.
255 bool GetPasswordSavingState() const;
256
257 // Returns whether the password bubble has been shown to the user.
258 bool GetManagePasswordsBubbleShownState() const;
259
260 const std::set<std::string>& BlockedResourcesForType( 208 const std::set<std::string>& BlockedResourcesForType(
261 ContentSettingsType content_type) const; 209 ContentSettingsType content_type) const;
262 210
263 // Returns the ContentSettingsUsagesState that controls the 211 // Returns the ContentSettingsUsagesState that controls the
264 // geolocation API usage on this page. 212 // geolocation API usage on this page.
265 const ContentSettingsUsagesState& geolocation_usages_state() const { 213 const ContentSettingsUsagesState& geolocation_usages_state() const {
266 return geolocation_usages_state_; 214 return geolocation_usages_state_;
267 } 215 }
268 216
269 // Returns the ContentSettingsUsageState that controls the MIDI usage on 217 // Returns the ContentSettingsUsageState that controls the MIDI usage on
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 int64 frame_id, 286 int64 frame_id,
339 int64 parent_frame_id, 287 int64 parent_frame_id,
340 bool is_main_frame, 288 bool is_main_frame,
341 const GURL& validated_url, 289 const GURL& validated_url,
342 bool is_error_page, 290 bool is_error_page,
343 bool is_iframe_srcdoc, 291 bool is_iframe_srcdoc,
344 content::RenderViewHost* render_view_host) OVERRIDE; 292 content::RenderViewHost* render_view_host) OVERRIDE;
345 virtual void AppCacheAccessed(const GURL& manifest_url, 293 virtual void AppCacheAccessed(const GURL& manifest_url,
346 bool blocked_by_policy) OVERRIDE; 294 bool blocked_by_policy) OVERRIDE;
347 295
348 void SavePassword();
349
350 const autofill::PasswordForm pending_credentials() const {
351 return form_manager_->pending_credentials();
352 }
353
354 const autofill::PasswordFormMap best_matches() const {
355 return password_form_map_;
356 }
357
358 // TODO(npentrel) This ought to be changed. Best matches should be newly
359 // made when opening the ManagePasswordsBubble because there may have been
360 // changes to the best matches via the settings page. At the moment this also
361 // fails if one deletes a password when they are autofilled, as it still shows
362 // up after logging in and saving a password.
363 void remove_from_best_matches(autofill::PasswordForm password_form) {
364 password_form_map_.erase(password_form.username_value);
365 }
366
367 bool password_submitted() const {
368 return password_submitted_;
369 }
370
371 void password_submitted(bool password_submitted) {
372 password_submitted_ = password_submitted;
373 }
374
375 // Message handlers. Public for testing. 296 // Message handlers. Public for testing.
376 void OnContentBlocked(ContentSettingsType type, 297 void OnContentBlocked(ContentSettingsType type,
377 const std::string& resource_identifier); 298 const std::string& resource_identifier);
378 void OnContentAllowed(ContentSettingsType type); 299 void OnContentAllowed(ContentSettingsType type);
379 300
380 // These methods are invoked on the UI thread by the static functions above. 301 // These methods are invoked on the UI thread by the static functions above.
381 // Public for testing. 302 // Public for testing.
382 void OnCookiesRead(const GURL& url, 303 void OnCookiesRead(const GURL& url,
383 const GURL& first_party_url, 304 const GURL& first_party_url,
384 const net::CookieList& cookie_list, 305 const net::CookieList& cookie_list,
(...skipping 23 matching lines...) Expand all
408 #endif 329 #endif
409 330
410 // This method is called to update the status about the microphone and 331 // This method is called to update the status about the microphone and
411 // camera stream access. |request_permissions| contains a list of requested 332 // camera stream access. |request_permissions| contains a list of requested
412 // media stream types and the permission for each type. 333 // media stream types and the permission for each type.
413 void OnMediaStreamPermissionSet( 334 void OnMediaStreamPermissionSet(
414 const GURL& request_origin, 335 const GURL& request_origin,
415 const MediaStreamDevicesController::MediaStreamTypeSettingsMap& 336 const MediaStreamDevicesController::MediaStreamTypeSettingsMap&
416 request_permissions); 337 request_permissions);
417 338
418 // Called when the user submits a form containing login information, so we
419 // can handle later requests to save or blacklist that login information.
420 // This stores the provided object in form_manager_ and triggers the UI to
421 // prompt the user about whether they would like to save the password.
422 void OnPasswordSubmitted(PasswordFormManager* form_manager);
423
424 // Called when a form is autofilled with login information, so we can manage
425 // password credentials for the current site which are stored in
426 // |password_form_map|. This stores a copy of |password_form_map| and shows
427 // the manage password icon.
428 void OnPasswordAutofilled(const autofill::PasswordFormMap& password_form_map);
429
430 // There methods are called to update the status about MIDI access. 339 // There methods are called to update the status about MIDI access.
431 void OnMIDISysExAccessed(const GURL& reqesting_origin); 340 void OnMIDISysExAccessed(const GURL& reqesting_origin);
432 void OnMIDISysExAccessBlocked(const GURL& requesting_origin); 341 void OnMIDISysExAccessBlocked(const GURL& requesting_origin);
433 342
434 // Is called to set ManagePasswordsIconController as an observer.
435 void SetPasswordObserver(PasswordObserver* observer);
436
437 // Adds the given |SiteDataObserver|. The |observer| is notified when a 343 // Adds the given |SiteDataObserver|. The |observer| is notified when a
438 // locale shared object, like for example a cookie, is accessed. 344 // locale shared object, like for example a cookie, is accessed.
439 void AddSiteDataObserver(SiteDataObserver* observer); 345 void AddSiteDataObserver(SiteDataObserver* observer);
440 346
441 // Removes the given |SiteDataObserver|. 347 // Removes the given |SiteDataObserver|.
442 void RemoveSiteDataObserver(SiteDataObserver* observer); 348 void RemoveSiteDataObserver(SiteDataObserver* observer);
443 349
444 private: 350 private:
445 explicit TabSpecificContentSettings(content::WebContents* tab); 351 explicit TabSpecificContentSettings(content::WebContents* tab);
446 friend class content::WebContentsUserData<TabSpecificContentSettings>; 352 friend class content::WebContentsUserData<TabSpecificContentSettings>;
447 353
448 void AddBlockedResource(ContentSettingsType content_type, 354 void AddBlockedResource(ContentSettingsType content_type,
449 const std::string& resource_identifier); 355 const std::string& resource_identifier);
450 356
451 // content::NotificationObserver implementation. 357 // content::NotificationObserver implementation.
452 virtual void Observe(int type, 358 virtual void Observe(int type,
453 const content::NotificationSource& source, 359 const content::NotificationSource& source,
454 const content::NotificationDetails& details) OVERRIDE; 360 const content::NotificationDetails& details) OVERRIDE;
455 361
456 // Notifies the registered PasswordObserver of a sumitted password form.
457 void NotifyPasswordObserver();
458
459 // Currently the registered PasswordObserver.
460 PasswordObserver* password_observer_;
461
462 // Notifies all registered |SiteDataObserver|s. 362 // Notifies all registered |SiteDataObserver|s.
463 void NotifySiteDataObservers(); 363 void NotifySiteDataObservers();
464 364
465 // All currently registered |SiteDataObserver|s. 365 // All currently registered |SiteDataObserver|s.
466 ObserverList<SiteDataObserver> observer_list_; 366 ObserverList<SiteDataObserver> observer_list_;
467 367
468 // Stores which content setting types actually have blocked content. 368 // Stores which content setting types actually have blocked content.
469 bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES]; 369 bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES];
470 370
471 // Stores if the blocked content was messaged to the user. 371 // Stores if the blocked content was messaged to the user.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 // The origin of the media stream request. Note that we only support handling 415 // The origin of the media stream request. Note that we only support handling
516 // settings for one request per tab. The latest request's origin will be 416 // settings for one request per tab. The latest request's origin will be
517 // stored here. http://crbug.com/259794 417 // stored here. http://crbug.com/259794
518 GURL media_stream_access_origin_; 418 GURL media_stream_access_origin_;
519 419
520 // The devices to be displayed in the media bubble when the media stream 420 // The devices to be displayed in the media bubble when the media stream
521 // request is requesting certain specific devices. 421 // request is requesting certain specific devices.
522 std::string media_stream_requested_audio_device_; 422 std::string media_stream_requested_audio_device_;
523 std::string media_stream_requested_video_device_; 423 std::string media_stream_requested_video_device_;
524 424
525 // Set by OnPasswordSubmitted() when the user submits a form containing login
526 // information. If the user responds to a subsequent "Do you want to save
527 // this password?" prompt, we ask this object to save or blacklist the
528 // associated login information in Chrome's password store.
529 scoped_ptr<PasswordFormManager> form_manager_;
530
531 // All previously stored credentials for a specific site. Set by
532 // OnPasswordSubmitted() or OnPasswordAutofilled().
533 autofill::PasswordFormMap password_form_map_;
534
535 bool manage_passwords_icon_to_be_shown_;
536 bool password_to_be_saved_;
537 bool manage_passwords_bubble_needs_showing_;
538 bool password_submitted_;
539
540 DISALLOW_COPY_AND_ASSIGN(TabSpecificContentSettings); 425 DISALLOW_COPY_AND_ASSIGN(TabSpecificContentSettings);
541 }; 426 };
542 427
543 #endif // CHROME_BROWSER_CONTENT_SETTINGS_TAB_SPECIFIC_CONTENT_SETTINGS_H_ 428 #endif // CHROME_BROWSER_CONTENT_SETTINGS_TAB_SPECIFIC_CONTENT_SETTINGS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698