OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/renderer/render_view.h" | 5 #include "chrome/renderer/render_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/gfx/png_encoder.h" | 12 #include "base/gfx/png_encoder.h" |
13 #include "base/gfx/native_widget_types.h" | 13 #include "base/gfx/native_widget_types.h" |
14 #include "base/string_piece.h" | 14 #include "base/string_piece.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/gfx/favicon_size.h" | 18 #include "chrome/common/gfx/favicon_size.h" |
19 #include "chrome/common/gfx/color_utils.h" | 19 #include "chrome/common/gfx/color_utils.h" |
20 #include "chrome/common/jstemplate_builder.h" | 20 #include "chrome/common/jstemplate_builder.h" |
21 #include "chrome/common/l10n_util.h" | 21 #include "chrome/common/l10n_util.h" |
22 #include "chrome/common/page_zoom.h" | 22 #include "chrome/common/page_zoom.h" |
23 #include "chrome/common/render_messages.h" | 23 #include "chrome/common/render_messages.h" |
24 #include "chrome/common/resource_bundle.h" | 24 #include "chrome/common/resource_bundle.h" |
25 #include "chrome/common/thumbnail_score.h" | 25 #include "chrome/common/thumbnail_score.h" |
26 #include "chrome/renderer/about_handler.h" | 26 #include "chrome/renderer/about_handler.h" |
27 #include "chrome/renderer/debug_message_handler.h" | 27 #include "chrome/renderer/debug_message_handler.h" |
28 #include "chrome/renderer/localized_error.h" | 28 #include "chrome/renderer/localized_error.h" |
| 29 #include "chrome/renderer/media/audio_renderer_impl.h" |
29 #include "chrome/renderer/render_process.h" | 30 #include "chrome/renderer/render_process.h" |
30 #include "chrome/renderer/user_script_slave.h" | 31 #include "chrome/renderer/user_script_slave.h" |
31 #include "chrome/renderer/visitedlink_slave.h" | 32 #include "chrome/renderer/visitedlink_slave.h" |
32 #include "chrome/renderer/webmediaplayer_delegate_impl.h" | 33 #include "chrome/renderer/webmediaplayer_delegate_impl.h" |
33 #include "chrome/renderer/webplugin_delegate_proxy.h" | 34 #include "chrome/renderer/webplugin_delegate_proxy.h" |
34 #include "net/base/escape.h" | 35 #include "net/base/escape.h" |
35 #include "net/base/net_errors.h" | 36 #include "net/base/net_errors.h" |
36 #include "skia/ext/bitmap_platform_device.h" | 37 #include "skia/ext/bitmap_platform_device.h" |
37 #include "skia/ext/image_operations.h" | 38 #include "skia/ext/image_operations.h" |
38 #include "webkit/default_plugin/default_plugin_shared.h" | 39 #include "webkit/default_plugin/default_plugin_shared.h" |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 IPC_MESSAGE_HANDLER(ViewMsg_PersonalizationEvent, OnPersonalizationEvent) | 402 IPC_MESSAGE_HANDLER(ViewMsg_PersonalizationEvent, OnPersonalizationEvent) |
402 #endif | 403 #endif |
403 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost, | 404 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost, |
404 OnMessageFromExternalHost) | 405 OnMessageFromExternalHost) |
405 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, | 406 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, |
406 OnDisassociateFromPopupCount) | 407 OnDisassociateFromPopupCount) |
407 IPC_MESSAGE_HANDLER(ViewMsg_AutofillSuggestions, | 408 IPC_MESSAGE_HANDLER(ViewMsg_AutofillSuggestions, |
408 OnReceivedAutofillSuggestions) | 409 OnReceivedAutofillSuggestions) |
409 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisiblityChanged, | 410 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisiblityChanged, |
410 OnPopupNotificationVisiblityChanged) | 411 OnPopupNotificationVisiblityChanged) |
| 412 IPC_MESSAGE_HANDLER(ViewMsg_RequestAudioPacket, OnRequestAudioPacket) |
| 413 IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamCreated, OnAudioStreamCreated) |
| 414 IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamStateChanged, |
| 415 OnAudioStreamStateChanged) |
| 416 IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamVolume, OnAudioStreamVolume) |
411 | 417 |
412 // Have the super handle all other messages. | 418 // Have the super handle all other messages. |
413 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message)) | 419 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message)) |
414 IPC_END_MESSAGE_MAP() | 420 IPC_END_MESSAGE_MAP() |
415 } | 421 } |
416 | 422 |
417 // Got a response from the browser after the renderer decided to create a new | 423 // Got a response from the browser after the renderer decided to create a new |
418 // view. | 424 // view. |
419 void RenderView::OnCreatingNewAck(gfx::NativeViewId parent) { | 425 void RenderView::OnCreatingNewAck(gfx::NativeViewId parent) { |
420 CompleteInit(parent); | 426 CompleteInit(parent); |
(...skipping 2435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2856 #endif // OS_WIN | 2862 #endif // OS_WIN |
2857 } | 2863 } |
2858 | 2864 |
2859 MessageLoop* RenderView::GetMessageLoopForIO() { | 2865 MessageLoop* RenderView::GetMessageLoopForIO() { |
2860 // Assume that we have only one RenderThread in the process and the owner loop | 2866 // Assume that we have only one RenderThread in the process and the owner loop |
2861 // of RenderThread is an IO message loop. | 2867 // of RenderThread is an IO message loop. |
2862 if (g_render_thread) | 2868 if (g_render_thread) |
2863 return g_render_thread->owner_loop(); | 2869 return g_render_thread->owner_loop(); |
2864 return NULL; | 2870 return NULL; |
2865 } | 2871 } |
| 2872 |
| 2873 void RenderView::OnRequestAudioPacket(int stream_id) { |
| 2874 AudioRendererImpl* audio_renderer = audio_renderers_.Lookup(stream_id); |
| 2875 if (!audio_renderer){ |
| 2876 NOTREACHED(); |
| 2877 return; |
| 2878 } |
| 2879 audio_renderer->OnRequestPacket(); |
| 2880 } |
| 2881 |
| 2882 void RenderView::OnAudioStreamCreated( |
| 2883 int stream_id, base::SharedMemoryHandle handle, int length) { |
| 2884 AudioRendererImpl* audio_renderer = audio_renderers_.Lookup(stream_id); |
| 2885 if (!audio_renderer){ |
| 2886 NOTREACHED(); |
| 2887 return; |
| 2888 } |
| 2889 audio_renderer->OnCreated(handle, length); |
| 2890 } |
| 2891 |
| 2892 void RenderView::OnAudioStreamStateChanged( |
| 2893 int stream_id, AudioOutputStream::State state, int info) { |
| 2894 AudioRendererImpl* audio_renderer = audio_renderers_.Lookup(stream_id); |
| 2895 if (!audio_renderer){ |
| 2896 NOTREACHED(); |
| 2897 return; |
| 2898 } |
| 2899 audio_renderer->OnStateChanged(state, info); |
| 2900 } |
| 2901 |
| 2902 void RenderView::OnAudioStreamVolume(int stream_id, double left, double right) { |
| 2903 AudioRendererImpl* audio_renderer = audio_renderers_.Lookup(stream_id); |
| 2904 if (!audio_renderer){ |
| 2905 NOTREACHED(); |
| 2906 return; |
| 2907 } |
| 2908 audio_renderer->OnVolume(left, right); |
| 2909 } |
| 2910 |
| 2911 int32 RenderView::CreateAudioStream(AudioRendererImpl* audio_renderer, |
| 2912 AudioManager::Format format, int channels, |
| 2913 int sample_rate, int bits_per_sample, |
| 2914 size_t packet_size) { |
| 2915 // TODO(hclam): make sure this method is called on render thread. |
| 2916 // Loop through the map and make sure there's no renderer already in the map. |
| 2917 for (IDMap<AudioRendererImpl>::const_iterator iter = audio_renderers_.begin(); |
| 2918 iter != audio_renderers_.end(); ++iter) { |
| 2919 DCHECK(iter->second != audio_renderer); |
| 2920 } |
| 2921 |
| 2922 // Add to map and send the IPC to browser process. |
| 2923 int32 stream_id = audio_renderers_.Add(audio_renderer); |
| 2924 ViewHostMsg_Audio_CreateStream params; |
| 2925 params.format = format; |
| 2926 params.channels = channels; |
| 2927 params.sample_rate = sample_rate; |
| 2928 params.bits_per_sample = bits_per_sample; |
| 2929 params.packet_size = packet_size; |
| 2930 Send(new ViewHostMsg_CreateAudioStream(routing_id_, stream_id, params)); |
| 2931 return stream_id; |
| 2932 } |
| 2933 |
| 2934 void RenderView::StartAudioStream(int stream_id) { |
| 2935 // TODO(hclam): make sure this method is called on render thread. |
| 2936 DCHECK(audio_renderers_.Lookup(stream_id) != NULL); |
| 2937 Send(new ViewHostMsg_StartAudioStream(routing_id_, stream_id)); |
| 2938 } |
| 2939 |
| 2940 void RenderView::CloseAudioStream(int stream_id) { |
| 2941 // TODO(hclam): make sure this method is called on render thread. |
| 2942 DCHECK(audio_renderers_.Lookup(stream_id) != NULL); |
| 2943 Send(new ViewHostMsg_CloseAudioStream(routing_id_, stream_id)); |
| 2944 } |
| 2945 |
| 2946 void RenderView::NotifyAudioPacketReady(int stream_id) { |
| 2947 // TODO(hclam): make sure this method is called on render thread. |
| 2948 DCHECK(audio_renderers_.Lookup(stream_id) != NULL); |
| 2949 Send(new ViewHostMsg_NotifyAudioPacketReady(routing_id_, stream_id)); |
| 2950 } |
| 2951 |
| 2952 void RenderView::GetAudioVolume(int stream_id) { |
| 2953 // TODO(hclam): make sure this method is called on render thread. |
| 2954 DCHECK(audio_renderers_.Lookup(stream_id) != NULL); |
| 2955 Send(new ViewHostMsg_GetAudioVolume(routing_id_, stream_id)); |
| 2956 } |
| 2957 |
| 2958 void RenderView::SetAudioVolume(int stream_id, double left, double right) { |
| 2959 // TODO(hclam): make sure this method is called on render thread. |
| 2960 DCHECK(audio_renderers_.Lookup(stream_id) != NULL); |
| 2961 Send(new ViewHostMsg_SetAudioVolume(routing_id_, stream_id, left, right)); |
| 2962 } |
OLD | NEW |