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 "content/renderer/render_view.h" | 5 #include "content/renderer/render_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/i18n/rtl.h" |
15 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
16 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
17 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
19 #include "base/process_util.h" | 20 #include "base/process_util.h" |
20 #include "base/string_piece.h" | 21 #include "base/string_piece.h" |
21 #include "base/string_util.h" | 22 #include "base/string_util.h" |
22 #include "base/sys_string_conversions.h" | 23 #include "base/sys_string_conversions.h" |
23 #include "base/time.h" | 24 #include "base/time.h" |
24 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 | 1172 |
1172 // Check if the navigation was within the same page, in which case we don't | 1173 // Check if the navigation was within the same page, in which case we don't |
1173 // want to clear the accessibility cache. | 1174 // want to clear the accessibility cache. |
1174 if (accessibility_.get() && !navigation_state->was_within_same_page()) { | 1175 if (accessibility_.get() && !navigation_state->was_within_same_page()) { |
1175 accessibility_.reset(); | 1176 accessibility_.reset(); |
1176 pending_accessibility_notifications_.clear(); | 1177 pending_accessibility_notifications_.clear(); |
1177 } | 1178 } |
1178 } | 1179 } |
1179 | 1180 |
1180 // Tell the embedding application that the title of the active page has changed | 1181 // Tell the embedding application that the title of the active page has changed |
1181 void RenderView::UpdateTitle(WebFrame* frame, const string16& title) { | 1182 void RenderView::UpdateTitle(WebFrame* frame, const string16& title, |
1182 // Ignore all but top level navigations... | 1183 WebTextDirection title_direction) { |
1183 if (!frame->parent()) { | 1184 // Ignore all but top level navigations. |
1184 Send(new ViewHostMsg_UpdateTitle( | 1185 if (frame->parent()) |
1185 routing_id_, | 1186 return; |
1186 page_id_, | 1187 |
1187 title.length() > content::kMaxTitleChars ? | 1188 string16 fixed_title = title.substr(0, content::kMaxTitleChars); |
1188 title.substr(0, content::kMaxTitleChars) : title)); | 1189 |
| 1190 // Wrap with extra Unicode formatting to make the title strongly directional. |
| 1191 if (!fixed_title.empty()) { |
| 1192 if (title_direction == WebKit::WebTextDirectionLeftToRight) { |
| 1193 // To avoid needing to complicate tests that only use ASCII characters, |
| 1194 // special-case out some known strongly directional characters. |
| 1195 char16 ch = fixed_title[0]; |
| 1196 bool first_char_is_already_strongly_ltr = |
| 1197 (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'); |
| 1198 if (!first_char_is_already_strongly_ltr) |
| 1199 base::i18n::WrapStringWithLTRFormatting(&fixed_title); |
| 1200 } else { |
| 1201 base::i18n::WrapStringWithRTLFormatting(&fixed_title); |
| 1202 } |
1189 } | 1203 } |
| 1204 |
| 1205 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, fixed_title)); |
1190 } | 1206 } |
1191 | 1207 |
1192 void RenderView::UpdateEncoding(WebFrame* frame, | 1208 void RenderView::UpdateEncoding(WebFrame* frame, |
1193 const std::string& encoding_name) { | 1209 const std::string& encoding_name) { |
1194 // Only update main frame's encoding_name. | 1210 // Only update main frame's encoding_name. |
1195 if (webview()->mainFrame() == frame && | 1211 if (webview()->mainFrame() == frame && |
1196 last_encoding_name_ != encoding_name) { | 1212 last_encoding_name_ != encoding_name) { |
1197 // Save the encoding name for later comparing. | 1213 // Save the encoding name for later comparing. |
1198 last_encoding_name_ = encoding_name; | 1214 last_encoding_name_ = encoding_name; |
1199 | 1215 |
(...skipping 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2533 if (frame == webview()->mainFrame()) | 2549 if (frame == webview()->mainFrame()) |
2534 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_)); | 2550 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_)); |
2535 } | 2551 } |
2536 | 2552 |
2537 FOR_EACH_OBSERVER(RenderViewObserver, observers_, | 2553 FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
2538 DidCreateDocumentElement(frame)); | 2554 DidCreateDocumentElement(frame)); |
2539 } | 2555 } |
2540 | 2556 |
2541 void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title, | 2557 void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title, |
2542 WebTextDirection direction) { | 2558 WebTextDirection direction) { |
2543 // TODO: pass direction through various APIs. | 2559 UpdateTitle(frame, title, direction); |
2544 // http://code.google.com/p/chromium/issues/detail?id=79903 | |
2545 UpdateTitle(frame, title); | |
2546 | 2560 |
2547 // Also check whether we have new encoding name. | 2561 // Also check whether we have new encoding name. |
2548 UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); | 2562 UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
2549 } | 2563 } |
2550 | 2564 |
2551 void RenderView::didChangeIcon(WebFrame* frame, WebIconURL::Type type) { | 2565 void RenderView::didChangeIcon(WebFrame* frame, WebIconURL::Type type) { |
2552 FOR_EACH_OBSERVER(RenderViewObserver, observers_, | 2566 FOR_EACH_OBSERVER(RenderViewObserver, observers_, |
2553 DidChangeIcon(frame, type)); | 2567 DidChangeIcon(frame, type)); |
2554 } | 2568 } |
2555 | 2569 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2600 // existing navigation state to a content-initiated navigation state. | 2614 // existing navigation state to a content-initiated navigation state. |
2601 // DidCreateDataSource conveniently takes care of this for us. | 2615 // DidCreateDataSource conveniently takes care of this for us. |
2602 didCreateDataSource(frame, frame->dataSource()); | 2616 didCreateDataSource(frame, frame->dataSource()); |
2603 | 2617 |
2604 NavigationState* new_state = | 2618 NavigationState* new_state = |
2605 NavigationState::FromDataSource(frame->dataSource()); | 2619 NavigationState::FromDataSource(frame->dataSource()); |
2606 new_state->set_was_within_same_page(true); | 2620 new_state->set_was_within_same_page(true); |
2607 | 2621 |
2608 didCommitProvisionalLoad(frame, is_new_navigation); | 2622 didCommitProvisionalLoad(frame, is_new_navigation); |
2609 | 2623 |
2610 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle()); | 2624 // TODO(evan): update this to use ->pageTitleDirection() once we pull in new |
| 2625 // WebKit. |
| 2626 // http://code.google.com/p/chromium/issues/detail?id=27094 |
| 2627 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle(), |
| 2628 WebKit::WebTextDirectionLeftToRight); |
2611 } | 2629 } |
2612 | 2630 |
2613 void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) { | 2631 void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) { |
2614 StartNavStateSyncTimerIfNecessary(); | 2632 StartNavStateSyncTimerIfNecessary(); |
2615 } | 2633 } |
2616 | 2634 |
2617 void RenderView::assignIdentifierToRequest( | 2635 void RenderView::assignIdentifierToRequest( |
2618 WebFrame* frame, unsigned identifier, const WebURLRequest& request) { | 2636 WebFrame* frame, unsigned identifier, const WebURLRequest& request) { |
2619 // Ignore | 2637 // Ignore |
2620 } | 2638 } |
(...skipping 1788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4409 } | 4427 } |
4410 #endif | 4428 #endif |
4411 | 4429 |
4412 void RenderView::OnContextMenuClosed( | 4430 void RenderView::OnContextMenuClosed( |
4413 const webkit_glue::CustomContextMenuContext& custom_context) { | 4431 const webkit_glue::CustomContextMenuContext& custom_context) { |
4414 if (custom_context.is_pepper_menu) | 4432 if (custom_context.is_pepper_menu) |
4415 pepper_delegate_.OnContextMenuClosed(custom_context); | 4433 pepper_delegate_.OnContextMenuClosed(custom_context); |
4416 else | 4434 else |
4417 context_menu_node_.reset(); | 4435 context_menu_node_.reset(); |
4418 } | 4436 } |
OLD | NEW |