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

Side by Side Diff: content/browser/web_contents/web_contents_impl.h

Issue 478543003: Use AudioStreamMonitor to control power save blocking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplify OS_CHROMEOS exclusions. Created 6 years, 3 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) 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 CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ 5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ 6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/containers/scoped_ptr_hash_map.h" 13 #include "base/containers/scoped_ptr_hash_map.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/observer_list.h" 16 #include "base/observer_list.h"
17 #include "base/process/process.h" 17 #include "base/process/process.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "content/browser/frame_host/frame_tree.h" 19 #include "content/browser/frame_host/frame_tree.h"
20 #include "content/browser/frame_host/navigation_controller_delegate.h" 20 #include "content/browser/frame_host/navigation_controller_delegate.h"
21 #include "content/browser/frame_host/navigation_controller_impl.h" 21 #include "content/browser/frame_host/navigation_controller_impl.h"
22 #include "content/browser/frame_host/navigator_delegate.h" 22 #include "content/browser/frame_host/navigator_delegate.h"
23 #include "content/browser/frame_host/render_frame_host_delegate.h" 23 #include "content/browser/frame_host/render_frame_host_delegate.h"
24 #include "content/browser/frame_host/render_frame_host_manager.h" 24 #include "content/browser/frame_host/render_frame_host_manager.h"
25 #include "content/browser/media/audio_stream_monitor.h"
25 #include "content/browser/renderer_host/render_view_host_delegate.h" 26 #include "content/browser/renderer_host/render_view_host_delegate.h"
26 #include "content/browser/renderer_host/render_widget_host_delegate.h" 27 #include "content/browser/renderer_host/render_widget_host_delegate.h"
27 #include "content/common/accessibility_mode_enums.h" 28 #include "content/common/accessibility_mode_enums.h"
28 #include "content/common/content_export.h" 29 #include "content/common/content_export.h"
29 #include "content/public/browser/color_chooser.h" 30 #include "content/public/browser/color_chooser.h"
30 #include "content/public/browser/notification_observer.h" 31 #include "content/public/browser/notification_observer.h"
31 #include "content/public/browser/notification_registrar.h" 32 #include "content/public/browser/notification_registrar.h"
32 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
33 #include "content/public/common/page_transition_types.h" 34 #include "content/public/common/page_transition_types.h"
34 #include "content/public/common/renderer_preferences.h" 35 #include "content/public/common/renderer_preferences.h"
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 virtual int DownloadImage(const GURL& url, 323 virtual int DownloadImage(const GURL& url,
323 bool is_favicon, 324 bool is_favicon,
324 uint32_t max_bitmap_size, 325 uint32_t max_bitmap_size,
325 const ImageDownloadCallback& callback) OVERRIDE; 326 const ImageDownloadCallback& callback) OVERRIDE;
326 virtual bool IsSubframe() const OVERRIDE; 327 virtual bool IsSubframe() const OVERRIDE;
327 virtual void Find(int request_id, 328 virtual void Find(int request_id,
328 const base::string16& search_text, 329 const base::string16& search_text,
329 const blink::WebFindOptions& options) OVERRIDE; 330 const blink::WebFindOptions& options) OVERRIDE;
330 virtual void StopFinding(StopFindAction action) OVERRIDE; 331 virtual void StopFinding(StopFindAction action) OVERRIDE;
331 virtual void InsertCSS(const std::string& css) OVERRIDE; 332 virtual void InsertCSS(const std::string& css) OVERRIDE;
333 virtual bool WasRecentlyAudible() OVERRIDE;
332 #if defined(OS_ANDROID) 334 #if defined(OS_ANDROID)
333 virtual base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents() 335 virtual base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents()
334 OVERRIDE; 336 OVERRIDE;
335 virtual WebContentsAndroid* GetWebContentsAndroid(); 337 virtual WebContentsAndroid* GetWebContentsAndroid();
336 #elif defined(OS_MACOSX) 338 #elif defined(OS_MACOSX)
337 virtual void SetAllowOtherViews(bool allow) OVERRIDE; 339 virtual void SetAllowOtherViews(bool allow) OVERRIDE;
338 virtual bool GetAllowOtherViews() OVERRIDE; 340 virtual bool GetAllowOtherViews() OVERRIDE;
339 #endif 341 #endif
340 342
341 // Implementation of PageNavigator. 343 // Implementation of PageNavigator.
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 // currently focused frame. 664 // currently focused frame.
663 void SelectRange(const gfx::Point& start, const gfx::Point& end); 665 void SelectRange(const gfx::Point& start, const gfx::Point& end);
664 666
665 // Notifies the main frame that it can continue navigation (if it was deferred 667 // Notifies the main frame that it can continue navigation (if it was deferred
666 // immediately at first response). 668 // immediately at first response).
667 void ResumeResponseDeferredAtStart(); 669 void ResumeResponseDeferredAtStart();
668 670
669 // Forces overscroll to be disabled (used by touch emulation). 671 // Forces overscroll to be disabled (used by touch emulation).
670 void SetForceDisableOverscrollContent(bool force_disable); 672 void SetForceDisableOverscrollContent(bool force_disable);
671 673
674 AudioStreamMonitor* audio_stream_monitor() {
675 return &audio_stream_monitor_;
676 }
677
678 bool has_audio_power_save_blocker_for_testing() const {
679 return audio_power_save_blocker_;
680 }
681
682 bool has_video_power_save_blocker_for_testing() const {
683 return video_power_save_blocker_;
684 }
685
672 private: 686 private:
673 friend class TestNavigationObserver; 687 friend class TestNavigationObserver;
674 friend class WebContentsAddedObserver; 688 friend class WebContentsAddedObserver;
675 friend class WebContentsObserver; 689 friend class WebContentsObserver;
676 friend class WebContents; // To implement factory methods. 690 friend class WebContents; // To implement factory methods.
677 691
678 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials); 692 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials);
679 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle); 693 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle);
680 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FindOpenerRVHWhenPending); 694 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FindOpenerRVHWhenPending);
681 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, 695 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest,
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 909
896 // TODO(creis): This should take in a FrameTreeNode to know which node's 910 // TODO(creis): This should take in a FrameTreeNode to know which node's
897 // render manager to return. For now, we just return the root's. 911 // render manager to return. For now, we just return the root's.
898 RenderFrameHostManager* GetRenderManager() const; 912 RenderFrameHostManager* GetRenderManager() const;
899 913
900 RenderViewHostImpl* GetRenderViewHostImpl(); 914 RenderViewHostImpl* GetRenderViewHostImpl();
901 915
902 // Removes browser plugin embedder if there is one. 916 // Removes browser plugin embedder if there is one.
903 void RemoveBrowserPluginEmbedder(); 917 void RemoveBrowserPluginEmbedder();
904 918
905 // Clear |render_frame_host|'s PowerSaveBlockers. 919 // Clear |render_frame_host|'s tracking entry for its power save blockers.
906 void ClearPowerSaveBlockers(RenderFrameHost* render_frame_host); 920 void ClearPowerSaveBlockers(RenderFrameHost* render_frame_host);
907 921
908 // Clear all PowerSaveBlockers, leave |power_save_blocker_| empty. 922 // Clear tracking entries for all RenderFrameHosts, clears
923 // |audio_power_save_blocker_| and |video_power_save_blocker_|.
909 void ClearAllPowerSaveBlockers(); 924 void ClearAllPowerSaveBlockers();
910 925
926 // Creates an audio or video power save blocker respectively.
927 void CreateAudioPowerSaveBlocker();
928 void CreateVideoPowerSaveBlocker();
929
930 // Releases the audio power save blockers if |active_audio_players_| is empty.
931 // Likewise, releases the video power save blockers if |active_video_players_|
932 // is empty.
933 void MaybeReleasePowerSaveBlockers();
934
911 // Helper function to invoke WebContentsDelegate::GetSizeForNewRenderView(). 935 // Helper function to invoke WebContentsDelegate::GetSizeForNewRenderView().
912 gfx::Size GetSizeForNewRenderView(); 936 gfx::Size GetSizeForNewRenderView();
913 937
914 void OnFrameRemoved(RenderFrameHost* render_frame_host); 938 void OnFrameRemoved(RenderFrameHost* render_frame_host);
915 939
916 // Helper method that's called whenever |preferred_size_| or 940 // Helper method that's called whenever |preferred_size_| or
917 // |preferred_size_for_capture_| changes, to propagate the new value to the 941 // |preferred_size_for_capture_| changes, to propagate the new value to the
918 // |delegate_|. 942 // |delegate_|.
919 void OnPreferredSizeChanged(const gfx::Size& old_size); 943 void OnPreferredSizeChanged(const gfx::Size& old_size);
920 944
945 // Helper methods for adding or removing player entries in |player_map| under
946 // the key |render_frame_message_source_|.
947 typedef std::vector<int64> PlayerList;
948 typedef std::map<uintptr_t, PlayerList> ActiveMediaPlayerMap;
949 void AddMediaPlayerEntry(int64 player_cookie,
950 ActiveMediaPlayerMap* player_map);
951 void RemoveMediaPlayerEntry(int64 player_cookie,
952 ActiveMediaPlayerMap* player_map);
953 // Removes all entries from |player_map| for |render_frame_host|.
954 void RemoveAllMediaPlayerEntries(RenderFrameHost* render_frame_host,
955 ActiveMediaPlayerMap* player_map);
956
921 // Adds/removes a callback called on creation of each new WebContents. 957 // Adds/removes a callback called on creation of each new WebContents.
922 // Deprecated, about to remove. 958 // Deprecated, about to remove.
923 static void AddCreatedCallback(const CreatedCallback& callback); 959 static void AddCreatedCallback(const CreatedCallback& callback);
924 static void RemoveCreatedCallback(const CreatedCallback& callback); 960 static void RemoveCreatedCallback(const CreatedCallback& callback);
925 961
926 // Data for core operation --------------------------------------------------- 962 // Data for core operation ---------------------------------------------------
927 963
928 // Delegate for notifying our owner about stuff. Not owned by us. 964 // Delegate for notifying our owner about stuff. Not owned by us.
929 WebContentsDelegate* delegate_; 965 WebContentsDelegate* delegate_;
930 966
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 // True if this tab was opened by another tab. This is not unset if the opener 1001 // True if this tab was opened by another tab. This is not unset if the opener
966 // is closed. 1002 // is closed.
967 bool created_with_opener_; 1003 bool created_with_opener_;
968 1004
969 #if defined(OS_WIN) 1005 #if defined(OS_WIN)
970 gfx::NativeViewAccessible accessible_parent_; 1006 gfx::NativeViewAccessible accessible_parent_;
971 #endif 1007 #endif
972 1008
973 // Helper classes ------------------------------------------------------------ 1009 // Helper classes ------------------------------------------------------------
974 1010
975 #if !defined(OS_CHROMEOS) 1011 // Tracking variables and associated power save blockers for media playback.
976 // Maps the RenderFrameHost to its media_player_cookie and PowerSaveBlocker 1012 ActiveMediaPlayerMap active_audio_players_;
977 // pairs. Key is the RenderFrameHost, value is the map which maps 1013 ActiveMediaPlayerMap active_video_players_;
978 // player_cookie on to PowerSaveBlocker. 1014 scoped_ptr<PowerSaveBlocker> audio_power_save_blocker_;
979 // 1015 scoped_ptr<PowerSaveBlocker> video_power_save_blocker_;
980 // ChromeOS does its own detection of audio and video.
981 typedef base::ScopedPtrHashMap<int64, PowerSaveBlocker>
982 PowerSaveBlockerMapEntry;
983 typedef base::ScopedPtrHashMap<uintptr_t, PowerSaveBlockerMapEntry>
984 PowerSaveBlockerMap;
985 PowerSaveBlockerMap power_save_blockers_;
986 #endif
987 1016
988 // Manages the frame tree of the page and process swaps in each node. 1017 // Manages the frame tree of the page and process swaps in each node.
989 FrameTree frame_tree_; 1018 FrameTree frame_tree_;
990 1019
991 // SavePackage, lazily created. 1020 // SavePackage, lazily created.
992 scoped_refptr<SavePackage> save_package_; 1021 scoped_refptr<SavePackage> save_package_;
993 1022
994 // Data for loading state ---------------------------------------------------- 1023 // Data for loading state ----------------------------------------------------
995 1024
996 // Indicates whether we're currently loading a resource. 1025 // Indicates whether we're currently loading a resource.
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 1223
1195 scoped_ptr<MidiDispatcherHost> midi_dispatcher_host_; 1224 scoped_ptr<MidiDispatcherHost> midi_dispatcher_host_;
1196 1225
1197 scoped_ptr<ScreenOrientationDispatcherHost> 1226 scoped_ptr<ScreenOrientationDispatcherHost>
1198 screen_orientation_dispatcher_host_; 1227 screen_orientation_dispatcher_host_;
1199 1228
1200 // The accessibility mode for all frames. This is queried when each frame 1229 // The accessibility mode for all frames. This is queried when each frame
1201 // is created, and broadcast to all frames when it changes. 1230 // is created, and broadcast to all frames when it changes.
1202 AccessibilityMode accessibility_mode_; 1231 AccessibilityMode accessibility_mode_;
1203 1232
1233 // Monitors power levels for audio streams associated with this WebContents.
1234 AudioStreamMonitor audio_stream_monitor_;
1235
1204 DISALLOW_COPY_AND_ASSIGN(WebContentsImpl); 1236 DISALLOW_COPY_AND_ASSIGN(WebContentsImpl);
1205 }; 1237 };
1206 1238
1207 } // namespace content 1239 } // namespace content
1208 1240
1209 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ 1241 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/audio_renderer_host.cc ('k') | content/browser/web_contents/web_contents_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698