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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc

Issue 73078: Fixing a crash which could occur when a string containing multibyte characters is p... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/autocomplete/autocomplete_edit_view_gtk.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 #include <gdk/gdkkeysyms.h> 8 #include <gdk/gdkkeysyms.h>
9 9
10 #include "base/gfx/gtk_util.h" 10 #include "base/gfx/gtk_util.h"
(...skipping 12 matching lines...) Expand all
23 const char kTextBaseColor[] = "#808080"; 23 const char kTextBaseColor[] = "#808080";
24 const char kSecureSchemeColor[] = "#009614"; 24 const char kSecureSchemeColor[] = "#009614";
25 const char kInsecureSchemeColor[] = "#c80000"; 25 const char kInsecureSchemeColor[] = "#c80000";
26 26
27 const GdkColor kBackgroundColorByLevel[] = { 27 const GdkColor kBackgroundColorByLevel[] = {
28 GDK_COLOR_RGB(255, 245, 195), // SecurityLevel SECURE: Yellow. 28 GDK_COLOR_RGB(255, 245, 195), // SecurityLevel SECURE: Yellow.
29 GDK_COLOR_RGB(255, 255, 255), // SecurityLevel NORMAL: White. 29 GDK_COLOR_RGB(255, 255, 255), // SecurityLevel NORMAL: White.
30 GDK_COLOR_RGB(255, 255, 255), // SecurityLevel INSECURE: White. 30 GDK_COLOR_RGB(255, 255, 255), // SecurityLevel INSECURE: White.
31 }; 31 };
32 32
33 size_t GetUTF8Offset(const std::wstring& wide_text, size_t wide_text_offset) {
34 return WideToUTF8(wide_text.substr(0, wide_text_offset)).size();
35 }
36
33 } // namespace 37 } // namespace
34 38
35 AutocompleteEditViewGtk::AutocompleteEditViewGtk( 39 AutocompleteEditViewGtk::AutocompleteEditViewGtk(
36 AutocompleteEditController* controller, 40 AutocompleteEditController* controller,
37 ToolbarModel* toolbar_model, 41 ToolbarModel* toolbar_model,
38 Profile* profile, 42 Profile* profile,
39 CommandUpdater* command_updater) 43 CommandUpdater* command_updater)
40 : tag_table_(NULL), 44 : tag_table_(NULL),
41 text_buffer_(NULL), 45 text_buffer_(NULL),
42 base_tag_(NULL), 46 base_tag_(NULL),
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 } 502 }
499 503
500 void AutocompleteEditViewGtk::EmphasizeURLComponents() { 504 void AutocompleteEditViewGtk::EmphasizeURLComponents() {
501 // See whether the contents are a URL with a non-empty host portion, which we 505 // See whether the contents are a URL with a non-empty host portion, which we
502 // should emphasize. To check for a URL, rather than using the type returned 506 // should emphasize. To check for a URL, rather than using the type returned
503 // by Parse(), ask the model, which will check the desired page transition for 507 // by Parse(), ask the model, which will check the desired page transition for
504 // this input. This can tell us whether an UNKNOWN input string is going to 508 // this input. This can tell us whether an UNKNOWN input string is going to
505 // be treated as a search or a navigation, and is the same method the Paste 509 // be treated as a search or a navigation, and is the same method the Paste
506 // And Go system uses. 510 // And Go system uses.
507 url_parse::Parsed parts; 511 url_parse::Parsed parts;
508 AutocompleteInput::Parse(GetText(), model_->GetDesiredTLD(), &parts, NULL); 512 std::wstring text = GetText();
513 AutocompleteInput::Parse(text, model_->GetDesiredTLD(), &parts, NULL);
509 bool emphasize = model_->CurrentTextIsURL() && (parts.host.len > 0); 514 bool emphasize = model_->CurrentTextIsURL() && (parts.host.len > 0);
510 515
511 // Set the baseline emphasis. 516 // Set the baseline emphasis.
512 GtkTextIter start, end; 517 GtkTextIter start, end;
513 gtk_text_buffer_get_bounds(text_buffer_, &start, &end); 518 gtk_text_buffer_get_bounds(text_buffer_, &start, &end);
514 gtk_text_buffer_remove_all_tags(text_buffer_, &start, &end); 519 gtk_text_buffer_remove_all_tags(text_buffer_, &start, &end);
515 if (emphasize) { 520 if (emphasize) {
516 gtk_text_buffer_apply_tag(text_buffer_, base_tag_, &start, &end); 521 gtk_text_buffer_apply_tag(text_buffer_, base_tag_, &start, &end);
517 522
518 // We've found a host name, give it more emphasis. 523 // We've found a host name, give it more emphasis.
519 gtk_text_buffer_get_iter_at_line_index(text_buffer_, &start, 0, 524 gtk_text_buffer_get_iter_at_line_index(text_buffer_, &start, 0,
520 parts.host.begin); 525 GetUTF8Offset(text,
526 parts.host.begin));
521 gtk_text_buffer_get_iter_at_line_index(text_buffer_, &end, 0, 527 gtk_text_buffer_get_iter_at_line_index(text_buffer_, &end, 0,
522 parts.host.end()); 528 GetUTF8Offset(text,
529 parts.host.end()));
523 gtk_text_buffer_remove_all_tags(text_buffer_, &start, &end); 530 gtk_text_buffer_remove_all_tags(text_buffer_, &start, &end);
524 } 531 }
525 532
526 // Emphasize the scheme for security UI display purposes (if necessary). 533 // Emphasize the scheme for security UI display purposes (if necessary).
527 if (!model_->user_input_in_progress() && parts.scheme.is_nonempty() && 534 if (!model_->user_input_in_progress() && parts.scheme.is_nonempty() &&
528 (scheme_security_level_ != ToolbarModel::NORMAL)) { 535 (scheme_security_level_ != ToolbarModel::NORMAL)) {
529 gtk_text_buffer_get_iter_at_line_index(text_buffer_, &start, 0, 536 gtk_text_buffer_get_iter_at_line_index(text_buffer_, &start, 0,
530 parts.scheme.begin); 537 GetUTF8Offset(text,
538 parts.scheme.begin));
531 gtk_text_buffer_get_iter_at_line_index(text_buffer_, &end, 0, 539 gtk_text_buffer_get_iter_at_line_index(text_buffer_, &end, 0,
532 parts.scheme.end()); 540 GetUTF8Offset(text,
541 parts.scheme.end()));
533 if (scheme_security_level_ == ToolbarModel::SECURE) { 542 if (scheme_security_level_ == ToolbarModel::SECURE) {
534 gtk_text_buffer_apply_tag(text_buffer_, secure_scheme_tag_, 543 gtk_text_buffer_apply_tag(text_buffer_, secure_scheme_tag_,
535 &start, &end); 544 &start, &end);
536 } else { 545 } else {
537 gtk_text_buffer_apply_tag(text_buffer_, insecure_scheme_tag_, 546 gtk_text_buffer_apply_tag(text_buffer_, insecure_scheme_tag_,
538 &start, &end); 547 &start, &end);
539 } 548 }
540 } 549 }
541 } 550 }
542 551
543 void AutocompleteEditViewGtk::TextChanged() { 552 void AutocompleteEditViewGtk::TextChanged() {
544 EmphasizeURLComponents(); 553 EmphasizeURLComponents();
545 controller_->OnChanged(); 554 controller_->OnChanged();
546 } 555 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698